Home Forums Support Simple Broadcast and Receive of Raw Bytes using UDP Reply To: Simple Broadcast and Receive of Raw Bytes using UDP

#2707
Anonymous
Inactive

Yes, I agree with your view on UDP protocol. What we have are a bunch of PLCs broadcasting UDP packets of raw bytes to the App on specific ports. The PLCs will broadcast if App is not listening.

Our problem occurs when we need to change the ports on which the App is listening. Here is the scenario where this will happen.

App starts up and creates a series of UDP listeners which are listening for PLCs that are not very smart and simply broadcast UDP packets to a specific port. For example, udpListenerA is listening on port 11000 for PLCA and udpListenerB is listening on 11001 for PLCB. The packet handlers are unique for udpListenerA and udpListenerB – in other words, they “know” who is sending them data (based on port) and are able to parse the incoming bytes accordingly. It is not possible to make a generic common packet handler because looking at raw bytes with no unique internal header information.

It appears that it is not possible to do the following:

On startup…
Get ports from App configuration.
nPortPLCA= 11000;
nPortPLCB= 11001;

Connection.StartListening(udpListenerA, new IPEndPoint(IPAddress.Any, nPortPLCA)),
Connection.StartListening(udpListenerB, new IPEndPoint(IPAddress.Any, nPortPLCB)),

… operator sees that APP is getting garbage data from both PLCA or PLCB and realizes that the problem is that someone has set the ports wrong, PLCA is actually broadcasting on 11001 and PLCB is broadcasting on 11000, so wants to change them.

if ( udpListenerA.IsListening )
Connection.StopListening(udpListenerA);
if ( udpListenerB.IsListening )
Connection.StopListening(udpListenerB);

Display configuration dialog that allows operator to change input ports, so now:
nPortPLCA= 11001;
nPortPLCB= 11000;
Save to App configuration, and now start listening on the “new” ports.

Connection.StartListening(udpListenerA, new IPEndPoint(IPAddress.Any, nPortPLCA)),
Connection.StartListening(udpListenerB, new IPEndPoint(IPAddress.Any, nPortPLCB)),

….but can’t do this because get exception error if try to “reuse” port 11001 (nPortPLCA).

As for recreating or reusing the listener. I have done both and get same error. Problem doesn’t seem to be with udpListener, but rather when calls Connection.StartListening( listener, <IP,port combo that has been used previously>);

If the solution is that I need to tell the Operator that he needs to restart the App if changes the input ports, then so be it. I would rather not if I’m just missing something obvious….

Thanks again.