954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Linux Network Programming - custom timeout value for a TCP socket?

From Beej's Guide to Network Programming:
How can I set a custom timeout value for a TCP or UDP socket?

It depends on your system. You might search the net for SO_RCVTIMEO and SO_SNDTIMEO (for use with setsockopt()) to see if your system supports such functionality.

The Linux man page suggests using alarm() or setitimer() as a substitute.

I'm interested in implementing a socket timeout using setitimer(), is there any sample code that does that? Thanks.

axfv
Newbie Poster
22 posts since Nov 2008
Reputation Points: 10
Solved Threads: 3
 

Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000);

So SocketOptionName has ReceiveTimeout/SendTimeout. Hope this will help you.


Albert

AlbertPi
Light Poster
33 posts since Nov 2008
Reputation Points: 9
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You