Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdUDPServer issue
(11-12-2018, 07:03 PM)BartKindt Wrote: Afterwards I got an exception caused by the other side: , UDPServer Exception: Socket Error # 10054Connection reset by peer.

You can't get that kind of error with UDP, since there is no connection.

You are binding your UDP server to an IP address that has "TCP" in its settings name. Are you, by chance, trying to bind the UDP server to the same IP/Port that is also being used by a TCP client/server? Not all platforms support that (Windows does, though).

(11-12-2018, 07:03 PM)BartKindt Wrote: I then call IdUDPServer1.Active := false; and I completely FreeAndNil it.

Then the loop starts again from fresh, with a newly created UDPServer.
However, now I get the Exception: Could not bind socket. Address and port are already in use

Why does this happen?

Because the previously bound IP/Port is still in use by the OS, obviously. The OS does not lie about that. Just because a socket is closed does not always mean its bound IP/Port is released right away. It may take a few minutes.

For your purposes, since you are running a server, try setting its ReuseSocket property to rsTrue. It is set to rsOSDependent by default, which resolves to rsTrue on Unix systems, and rsFalse on others (such as Windows).

(11-12-2018, 07:03 PM)BartKindt Wrote: Should I somehow manually clear the sockets before setting the Active to False?

No, not before. But, you typically should clear the Bindings after setting Active to False and before repopulating the Bindings. But, if you are not going to change any settings, you just want to reactivate using the same IP/Port pairs, then you don't need to clear the Bindings.


Messages In This Thread
IdUDPServer issue - by BartKindt - 11-12-2018, 07:03 PM
RE: IdUDPServer issue - by rlebeau - 11-13-2018, 07:29 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)