I have a server that streams data out on a TCP port once you connect to it. You can see this if you telnet to the TCP port and data starts flowing.
I am looking for an example that will let me connect to an IP address and port and receive the data in a stream in the application.
All examples I can find are with a client-server model with the client sending (which is not what I need) and the server binding to a port on itself and receiving.
I need this to be asynchronous and believe this can be done, but I could do with a good leg up!
If you are using a
TcpClient, usingGetStreamfor getting theNetworkStreamand then use the stream for reading the data sent by the server. You can always use the stream asynchronously, usingBeginRead.If you are using a plain old
Socket, you can useBeginReceiveto receive asynchronously once connected.Either way, as soon as you have a
NetworkStreamor aSocketobject that is bound and connected, there is no difference between the server or the client. You can use the server example of reading in the client code, most often with no (or little) modification.For an example: