Home Forums Support UDP – Restart Listener

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4166
    Anonymous
    Inactive

    Hello,

    I have problem while using the UDPConnectionListener. If I StopListening() and want to StartListening() for the same IPEndPoint again, an unhandled exception occures. The exception says:

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

    Init UDP Listener:

    SendReceiveOptions optionsToUseForUDPInput = new SendReceiveOptions<NetworkCommsDotNet.DPSBase.NullSerializer>();
    udpListener = new UDPConnectionListener(optionsToUseForUDPInput, ApplicationLayerProtocolStatus.Disabled, UDPOptions.None);
    udpListener.AppendIncomingUnmanagedPacketHandler(handleIncomingUDPPackage);

    Code for Button which Start Listener:

    Connection.StartListening(udpListener, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 4001));

    Code for Button which Stops Listener:

    Connection.StopListening(udpListener);

    Until here, everything works fine. But if I click on the Start Button again, the exception mentioned above throws.

    Funny fact: The following code works without problems (if you write the Start/Stop/Start in one button:

    Connection.StartListening(udpListener, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 4001));
    Connection.StopListening(udpListener);
    Connection.StartListening(udpListener, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 4001));

    Thanks for your help in advance.

    #4177
    Anonymous
    Inactive

    Heya Patrick,

    Are you call stop listening you may have to recreate the UDPListener instance. i.e. in your start listening button event create a new udplistener.

    Kind regards,
    Marc

    #4181
    Anonymous
    Inactive

    Hi Marc,

    thanks for your answer.

    Unfortunately this doesn’t work.

    I create a new UDPListener-Instance and call StartListening(…).

    It throws the same exception:

    NetworkCommsDotNet.ConnectionSetupException: A UDP connection already exists with info [UDP-D-U] 0.0.0.0:4001 -> 0.0.0.0:0

    I tried several different approaches but can’t find a way to reopen a UDP Listener at the same port if it was closed before.

    Can you please send me your code? I am sure you tested it already.

    Thanks!

    • This reply was modified 8 years, 6 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.