日期:2014-05-18  浏览次数:20437 次

这段代码报错,疑惑。。。
C# code

Socket   sock   =   new   Socket(AddressFamily.InterNetwork,   SocketType.Stream,   ProtocolType.Tcp); 
sock.Connect(new   IPEndPoint(IPAddress.Parse( "222.45.12.55 "),   5001)); 

if(sock.Connected) 
{ 
          byte[]   buff   =   Encoding.ASCII.GetBytes(strSendMessage); 
          sock.Send(buff,   0,   buff.Length,   SocketFlags.None);     
          
          byte[]   recvBuff   =   new   byte[2048]; 
          int   bytes   =   sock.Receive(buff,   0,   recvBuff.Length,   SocketFlags.None);     
          string   rs   =   Encoding.ASCII.GetString(buff,   0,   bytes); 
          //接受到的字符串 
} 
sock.Close(); 




指定的参数已超出有效值的范围。参数名: size

------解决方案--------------------
上限减1
------解决方案--------------------
关注
------解决方案--------------------
探讨
 int bytes = sock.Receive(recvBuff, 0, recvBuff.Length, SocketFlags.None);


------解决方案--------------------