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


Hi Marc – Thanks for reply. Just getting back to this now and can send/receive unmanaged UDP packets using this code snippet. That’s great, but now I have some housekeeping questions for UDP input.

I’m not clear on open, close and reopening of connection with your code example.

I create the udpListener with udpListener= UDPConnectionListener(…), and then start listening on a specific port with Connection.StartListening(udpListener, new IPEndPoint(IPAddress.Any, 10000)) and then append a packet handler routine. The listener is up and running and my third-party device can transmit raw bytes to this listener.

That’s great, but now what about closing the connection and reopening? Currently, I remove the packet handler routine with udpListener.RemoveIncomingUnmanagedPacketHandler() and then stop listening with Connection.StopListening(udpListener).

I can start listening on a different port, but if I try to start listening again on the same port, i.e. Connection.StartListening(udpListener, new IPEndPoint(IPAddress.Any, 10000)), I get an exception error as follows:

An unhandled exception of type ‘NetworkCommsDotNet.ConnectionSetupException’ occurred in NetworkCommsDotNetComplete.dll

Additional information: A UDP connection already exists with info [UDP-D-U] ->

My question is:

How do I start listening, stop listening and the start listening again – or better yet how do you close a UDPConnectionListener other than calling NetworkComms.Shutdown() ?

It looks like there are ways to handle this when creating managed UDP connections with new ConnectionInfo(…) and UDPConnection.GetConnection(…) because you can call CloseConnection() etc… but you don’t have the same ability when create unmanaged UDP connections with new UDPConnectionListener(…)

Everything seems fine if call NetworkComms.Shutdown() and then start it back up again, but I would rather not have to restart all network comms because needing to change input port for a single listener.

Thanks in advance.