Now test conditions are as follows:
1, and others to send data on your computer use udp debugging assistants can receive, but his writing of udp accept less than
2, udp sends data someone else can get
3, on your computer using udp debugging assistant to send data, write their own udp to receive
4, write their own udp in other solution could be received, but in the current solution is not receive
Ask god to help see what reason, have not received the data in the receive there directly, the same IP and port number to use the Internet to download debugging assistants will receive, the code is as follows:
String localIP="";//the machine IP
IPAddress []=IP Dns. GetHostAddresses (Dns. The GetHostName ());//get the local IP address list
for (int i=0; i
LocalIP=IP [I] the ToString ();
}
# region UDP receives the thread open
LocalRevEndPoint=new IPEndPoint (IPAddress. Parse (localIP), Myapp_Config. PortRev_l);//local receiving endpoints
ReceiveThread=new Thread (new ThreadStart (UDPReceive));//UDP receives the thread
ReceiveThread. IsBackground=true;
ReceiveThread. Name="UDP receiving threads";
ReceiveThread. Start ();
# endregion
///& lt; Summary>
///receiving data
///& lt;/summary>
Private void UDPReceive ()
{
IPEndPoint remoteIpEndPoint=new IPEndPoint (IPAddress. Any, 0);//remote endpoint of any IP
ReceiveUdpClient=new UdpClient (LocalRevEndPoint);
While (true)
{
Try
{
Byte [] receiveBytes=ReceiveUdpClient. The Receive (ref remoteIpEndPoint);//receiving data
Console. WriteLine (" receiving data ");
If (receiveBytes [0]==0 XFF & amp; & ReceiveBytes [1]==0 xee)
{
RevDateTime=DateTime. Now;//for receiving data time
String RemoteIP=remoteIpEndPoint. Address. The ToString ();
If (receiveBytes. Length & gt; 0 & amp; & RemoteIP!="")
{
MenuForm. MyTransSystemState. SystemState (receiveBytes, RemoteIP);//processing system state data
}
}
}
The catch (Exception ex)
{
//m_SysException. SystemException (ex, ""," UdpServer. Listen ");
Console. WriteLine (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");
Console. WriteLine (ex. ToString ());
}
Thread.sleep (500);
}
}
CodePudding user response:
ReceiveUdpClient this is what the, the top that string loop IP also don't know what is
So to speak, you just need to start listening is good, so please open a fixed port IP. Any is ok, but you may Receive, don't know what you write is above the scarlet letter part, so no answer
CodePudding user response:
Oh, etc., console, threadI estimate is not received, I estimate is no output
CodePudding user response: