locked
Sockets connection failure timeout RRS feed

  • Question

  • Dear All,

    I am trying to use connection-oriented (TCP) sockets (Windows XP environment) for my client-server applications communicating over Ethernet. My question is about connection failure timeout. Namely, in case the sockets connection is installed and normal data exchange is going on.

    If the low level (Ethernet) connection trouble happens, for example heavy traffic congestion or transient ethernet switch problem is encountered, or ethernet cable is temporarily removed on client or server, what is the timeout after which the socket connection is lost? How this timeout parameter can be read and set?

     

    Many thanks

     

    Tuesday, November 1, 2011 12:53 PM

Answers

  • Hi,

     

    If you use TcpClient then you can set the SendTimeout and ReceiveTimeout.

    But if you are using raw sockets then:

    For connection failure detection you can use Socket.BeginConnect.. and Socket.EndConnect.

    The IAsyncResult of Begin Connect can be given to  Thread in the ThreadPool and Queue an item to wait for successful connection.

    ThreadPool.QueueUserWorkItem(CallbackForTimeout, new object[] { result, timeout });

    you need to implement the CallbackForTimeout code.

    when receiving the messages you can use the following:

    socketObject.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeoutValue);

    I recommend using Tcpclient.. it servers most of the purpose at the same speed.

    Regards

    Kajal

     


    Kajal Sinha
    • Edited by Kajal Sinha Friday, November 4, 2011 3:25 AM Additional comments
    • Marked as answer by ShieldGuy Friday, November 4, 2011 11:40 AM
    Friday, November 4, 2011 3:21 AM