设置一个buf,每次只读取指定长度的数据量

解决方案 »

  1.   

    发送Buffer的接收有一致,如:
    //发送:
     byte[] sendInfo = new byte[1024];
     sendInfo        = System.Text.UnicodeEncoding.Default.GetBytes(Message.ToCharArray());
     i               = socket.Send(sendInfo,sendInfo.Length ,0);
    //接收
    byte[] serverInfo = new byte[1024];
     int i             = socket.Receive(serverInfo,serverInfo.Length ,SocketFlags.None);
                   string infoTo     = System.Text.UnicodeEncoding.Default.GetString(serverInfo);
      

  2.   

    TCP is stream based transmission protocol. It doesn't have the concept of "packet". All data are guaranteed to arrive destination in order, but not always orgnized into the same data trunk.
      On the other hand, UDP always guarantees that packets arrive in its full size and one packet at a time.  So, maybe you should use UDP instead of TCP.
      

  3.   

    you can use udpclient;
    UdpClient receivingUdpClient = new UdpClient();
    Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
      

  4.   

    自己设置一个bool来判断,如果收到一个就false了嘛……哈哈,乱说而已