日期:2014-05-18 浏览次数:20955 次
UdpClient udp = new UdpClient(5000);
ip: 远程设备的地址: 192.168.7.100 port 远程: 3000 public byte[] DeviceComunicationTest(string ip,int Port, byte[] Cmd, int len) { udp.Connect(ip, Port); udp.Send(Cmd, len); byte[] receive = new byte[256]; return UdpReceiveData(ip, port);// 接受设备返回数据 }
public byte[] UdpReceiveData(string ip,int LocalPort) { ipadr = new IPEndPoint(IPAddress.Parse(ip), LocalPort); return udp.Receive(ref ipadr); }
byte[] receive = new byte[256]; receive = DeviceComunicationTest(xx,xx,xx); // 处理 receive返回来的数据
udp.Connect(ip, Port);
public byte[] UdpReceiveData(string ip,int LocalPort) { ipadr = new IPEndPoint(IPAddress.Parse(ip), LocalPort); return udp.Receive(ref ipadr); //代码死在上面这句上了 }