I have a question regarding a TCP Connection Class I'm writing.
The Connection Class I already wrote can establish a connection via TCP. It listens and writes to that connection from two different threads. Now I want to improve that class.
I want to establish this connection fully asynchronous so that the connection can be establishes while other things in my application will be prepared. But I have some other Classes which needs an established connection to work properly. So, my question is, could someone explain me with an little example how I could establish the connection asynchronous with the possibility that an other class starts to work after the connection is established?
My first idea was to fire an event after the TCP Client is connected but then I got in trouble with the fact, that the connection is only fully established if the remote server sends a message back. After that I got an idea to create a connection state. But now I don't know how to proceed further.
If it's not the way how to use await and async please let me know.
Thanks in advance, Patrick
Edit:
Thanks for your answers. To clarify things I want to update my post.
As someone requested what I have so far, I posted my source code at GitHub. In Line 46 I set the connection state to Connecting. After the TCP connection is established I change the status to Fetching (L155). Now I have to wait for the message which indicates that the connection is fully ready. After the Message came I expected I set the State to Open (L315) and fire an ConnectionEstablished Event.
Please excuse but I can't post more than 2 links.