日期:2014-05-18 浏览次数:21128 次
public void udpSendCommands2(string IP, int Port, byte[] Cmd, int len) { udp.Connect(IP, Port); udp.Send(Cmd, len); }
private void button2_Click(object sender, EventArgs e) { ul.udpSendCommands2(ip,port,cmd,len) try { startServer = new Thread(new ThreadStart(startUdpServer)); startServer.Start(); } catch (ThreadAbortException) { MessageBox.Show("error"); } }
public void startUdpServer() { byte[]buffer= new byte[1024]; buffer = UdpReceiveData(ip, port); //显示buffer从0到len的内容 if (buffer[0] == 0xf0) { dosomething(buffer); } }
public byte[] UdpReceiveData(string IP, int Port) { udpIpadr = new IPEndPoint(IP, Port); return udp.Receive(ref udpIpadr); }