Regarding your questions, I am going to recommend taking a look at some of the examples from SwiftNIO, as it looks like you may have based your implementation above on either NIOChatClient or NIOEchoClient. Now, I will provide you initial instruction here, but for any additional help with the internals of SwiftNIO it would be best to open an issue on their repo or ask for additional clarification in the Swift Forums with the SwiftNIO tag. If you do open an issue on the SwiftNIO repo, then please follow up here the the issue number.
As for your questions:
// Q1 Are these declarations correct?
Honestly, this is hard to say one way or another without the entire picture, but if you compare it against the samples I mentioned above, then yes, this should at least allow you to get an TCP connection off the ground via IP. If you are having issues reading and checking the state of your connection make sure the ChannelInboundHandler
functions are implemented, so this functionality is available to your connection.
Regarding:
// Q2 How to change to the correct thread - and return to main?
// Q3 How to change to the correct thread - and return to main?
First, unless you have specified in your code that this entire class is operating on a separate thread, it would be helpful for you to get a quick sanity check to know if this is already the main or not. Having said that, one approach is to create a delegate pipeline that sends updates back to your ViewModel here to they can eventually make it to the UI. You could define specific functions that deal with connection state, reading / writing of data on your connection, or you could just use one function to handle all updates, and then dispatch these updates to the main.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com