C# C/S 客户端不能正确接收服务器发来的第二次数据
在登陆过程中客户端新建了个线程来和服务器会话
private void 登陆_Load(object sender, EventArgs e)
{
contactWithServer = new ContactWithServer(this, user);
Thread clientcontactserverThread = new Thread(new ThreadStart(contactWithServer.contact));
clientcontactserverThread.Start();
}
客户端接收程序
public void contact()
{
//receiveIpep = new IPEndPoint(IPAddress.Parse(serverIP), 8888);
////sendIpep = new IPEndPoint(IPAddress.Parse(serverIP), 6666); //服务器端接收端口
//udpReceiveClient = new UdpClient(receiveIpep);
receiveIpep = null;
try
{
udpReceiveClient = new UdpClient(8888);
while (true)
{
MessageBox.Show("where");
byte[] data = udpReceiveClient.Receive(ref receiveIpep);
if (data.Length < 20) //只有命令
commandStr = Encoding.ASCII.GetString(data);
else //既有命令又有数据
{