C# C/S登陆模块 服务器不识别客户端的请求
在客户端:
command = Encoding.ASCII.GetBytes("Login"); //命令
for (int i = 0; i < command.Length; i++)
{
cmd[i]=command[i];
}
memStream = new MemoryStream();
formatter.Serialize(memStream, user);
memStream.Flush();
data = memStream.ToArray(); //将User对象序列化发送给服务器
buffer=new byte[cmd.Length+data.Length];
Array.Copy(cmd,0,buffer,0,cmd.Length);
Array.Copy(data,0,buffer,cmd.Length,data.Length);
contactWithServer.sendData(buffer,buffer.Length);
public void sendData(byte[] data,int len)
{
udpSendClient.Send(data,len,sendIpep);
}
服务器端:
data = receiveUdpClient.Receive(ref receiveIpep);
MessageBox.Show(data.Length.ToString(),"数据长度");
int i = 0;