ROBERT RICHARDSON
ROBERT RICHARDSON

Reputation: 2279

What to do after TcpListener times out?

It seems really strange that I can't seem to find an answer to this question. When trying to use a TcpListener in a C# windows forms application, I can set timeouts on a TcpListener's Server object, but what do I do when a timeout occurs? How do I recognize that it happened? In low-level socket programming in Python, I can specify a timeout event handler, but I don't see a way to do that in C#.

Upvotes: 0

Views: 204

Answers (1)

Luaan
Luaan

Reputation: 63732

The SendTimeout value is only used when using the synchronous Send. When the timeout is hit, Send will throw a SocketException - that's how you know the Send failed.

In practice, you shouldn't really do anything with the underlying winsocket object - all you should need in almost all cases are the methods and properties exposed by TcpListener and TcpClient themselves.

Upvotes: 2

Related Questions