How to handle multiple TcpClient clients simultaneously

318 views Asked by At

I usually write my socket apps with UdpClient, I like the way udp works. I just listen on a socket, anytime anyone has a request, I just get a little datagram, reply right back to that client via their IpEndPoint.

But with TcpListener it's seemingly much more complicated. I have to wait for someone to connect (via server.AcceptTcpClient()), then setup a while loop to receive data until there is no more data from the accepted client. Finally, close() the connection.

Is there a way to keep multiple connections open and receive bits of data without closing the connection at the end? It just seems so weird how much more complicated TCP is than UDP.

thoughts?

0

There are 0 answers