连接尝试失败,因为连接方在一段时间后没有正确响应,

时间:2011-04-26 12:09:26

标签: c# sockets tcpclient

我无法连接远程服务器,我应该从服务器接收十六进制05格式数据并建立连接,但我无法得到正确的响应。

          IPAddress[] oIPAddress = Dns.GetHostAddresses("serveraddress");
        IPEndPoint oIPEnd = new IPEndPoint(oIPAddress[0], 5002);
        Socket ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        ClientSocket.Connect(oIPEnd);
        //SocketOptionLevel();
        SocketOptionLevel level = new SocketOptionLevel();
        SocketOptionName ReceievTimeout=new SocketOptionName();

        ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress,true);
        ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 120);

        byte[] servermsg = new byte[ClientSocket.ReceiveBufferSize];
        int len=ClientSocket.Receive(servermsg);
        string cD= System.Text.Encoding.ASCII.GetString(servermsg);
        Response.Write(cD.ToString());

这是一个错误,我正在

System.Net.Sockets.SocketException:连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应System.Net.Sockets.Socket.Receive (字节[]缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags)在System.Net.Sockets.Socket.Receive(Byte []缓冲区)处于_Default.Page_Load(Object sender,EventArgs e)的e:\ SocketProg \ Default中。 aspx.cs:第44行

你可以建议我......

谢谢

0 个答案:

没有答案