帮忙看两段代码,看怎样可以建立起通讯关系。我在调试是总是出错!
服务器端:
UdpClient udpClient = new UdpClient( "127.0.0.1 ",6061);//
IPAddress hostIp = IPAddress.Parse( "192.168.1.103 ");
IPEndPoint server = new IPEndPoint(hostIp, 6602);
string m = "发送服务器信息 ";
Byte[] sendBytes = Encoding.ASCII.GetBytes(m);
udpClient.Send(sendBytes, sendBytes.Length, server);
客户端:
UdpClient udpClient = new UdpClient( "192.168.1.103 ",6602);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse( "127.0.0.1 "), 6601);
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
textBox1.Text = returnData.ToString();
------解决方案--------------------Send必须先用Connect才能用