tleylan

tleylan
- Name: [not set]
- Favorite Languages: [not set]
- Website: [not set]
- Location: [not set]
- About Me: [not set]
-
C# Tutorial - Simple Threaded TCP Server
08/19/2010 - 11:41
Just a quick note to offer a solution to the blocking call to AcceptTcpClient(). The TCPListener class has a Pending() method indicating whether there is a client to accept.
I added a Boolean property "listening" to control the loop (rather than using "true"). Inside the loop there is a call to Pending() and only if that returns true is there a call to AcceptTcpClient() which should not block.
When you need to stop the server set Listening to false. The loop exits and we an opportunity to call tcpListener.Stop().
Log files confirms that it is working for me...
Recent Comments