Home > Net >  C # udp communication not receive data from the others
C # udp communication not receive data from the others

Time:11-17

Debugging before is to receive, then nothing change, also to the IP address and port number, is to close not to,

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, thread

I estimate is not received, I estimate is no output

CodePudding user response:

refer to the second floor wanghui0380 response:
oh, etc., console, thread

I estimate is not received, I estimate is no output
that sounds like the received, beat breakpoints in ReceiveUdpClient. Receive and then don't go down there

CodePudding user response:

reference 1st floor wanghui0380 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
ReceiveUdpClient is the instantiation of a UdpClient global variables, port and IP right
Private UdpClient ReceiveUdpClient;//receiving UDP

CodePudding user response:

Don't get one? Write the while (true) Thread. Sleep is a pit, others may have been sent, you delay this part could have close not to, suggest to UdpClient. BeginReceive

CodePudding user response:

The
big watermelon a WuYiJin reference 5 floor? Response:
a are not receive? Write the while (true) Thread. Sleep is a pit, others may have been sent, you delay this part could have close not to, suggest to UdpClient. BeginReceive
receives less than one, put the Thread. Sleep, unable to delete the breakpoint into not to go

CodePudding user response:

Problem has been solved, is accidentally opened the firewall, is really helpless

CodePudding user response:

Standing rule change
  •  Tags:  
  • C#
  • Related