string sTime = DateTime.Now.ToShortTimeString ( ) ;
//获取接收数据时的时间
Byte [ ] byRead =new Byte [ 80 ] ;
int iRead = stRead.ReceiveFrom
( byRead , ref tempRemoteEP ) ;
//获得接收的字节数目
Byte [ ] byText = new Byte [ iRead ] ;
//并根据接收到的字节数目来定义字节数组
Array.Copy ( byRead , 0 , byText , 0 , iRead ) ;
string sTemp = System.Text.Encoding.Default.
---------------sock接受数据.如果一开始接受的数据量打于80,怎么办?
能否Byte [ ] byRead =new Byte [ 80 ] ;开辟空间时就根据接受到的数据来?
//获取接收数据时的时间
Byte [ ] byRead =new Byte [ 80 ] ;
int iRead = stRead.ReceiveFrom
( byRead , ref tempRemoteEP ) ;
//获得接收的字节数目
Byte [ ] byText = new Byte [ iRead ] ;
//并根据接收到的字节数目来定义字节数组
Array.Copy ( byRead , 0 , byText , 0 , iRead ) ;
string sTemp = System.Text.Encoding.Default.
---------------sock接受数据.如果一开始接受的数据量打于80,怎么办?
能否Byte [ ] byRead =new Byte [ 80 ] ;开辟空间时就根据接受到的数据来?
Byte [ ] byRead =new Byte [ 80 ] ;
int iRead = stRead.ReceiveFrom
( byRead , ref tempRemoteEP ) ;
这样是一次接受80
可以做个循环接受 直到收到的数据为0
string recvString="";
//声明字节数组,一次接收数据的长度为1024字节
byte[] recvBytes=new byte[1024];
//返回实际接收内容的字节数
int bytes=0;
//循环读取,直到接收完所有数据
while(true)
{ bytes=s.Receive(recvBytes,recvBytes.Length,0);
//读取完成后退出循环
if(bytes<=0)
break;
//将读取的字节数转换为字符串
recvString+=Encoding.ASCII.GetString(recvBytes,0,bytes);
}