请指教,最好给出简单代码

解决方案 »

  1.   

    Use "Socket.SetSocketOption" to receive timeout and send timeout
      

  2.   

    Sample code as follows:
    //Send operations will timeout of confirmation is not received within 1000 milliseconds.
    s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
      

  3.   

    Use try-catch to send data or receive data.
      

  4.   

    try{
     ...
     ...
     ...
     ...
     ...
     ...
    }
    catch(SocketException se)
    {
        if(se.ErrorCode == 10060)
        {
            //超时处理
        }
    }
      

  5.   

    SetSocketOption  我用过,但好像不起作用啊。
      

  6.   


    mClient.Client.SendTimeout = 1000000;
                mClient.Client.ReceiveTimeout = 20000;
      

  7.   

    Socket sock=....;
    sock.SendTimeout=1000;//1 second
    sock.ReceiveTimeout=2000;//1 second
    .net 2.0支持。
    用socket最好用.net 2.0。能减少很多工作量。