TsgcUDPServerMethods › RemoveBinding

RemoveBinding Method

Removes the listening endpoint matching the given IP/port and closes its socket without stopping the server.

Syntax

function RemoveBinding(const aIPAddress: string; aPort: Integer): Boolean;

Parameters

NameTypeDescription
aIPAddressconst stringLocal IP address of the binding to remove. Must match an IP previously passed to AddBinding (or the IP of an existing Bindings entry).
aPortIntegerLocal UDP port of the binding to remove.

Return Value

True when a matching binding was found and removed; False when no entry with the supplied IP and port exists. (Boolean)

Remarks

RemoveBinding stops the listener thread for the matching endpoint, closes the datagram socket and deletes the entry from Bindings, without affecting any other binding served by the component. It is the runtime counterpart of AddBinding and is typically used to drop a redundant interface or to rotate the listening port without calling ReStart. The method requires Indy 10.2 or later and raises an exception on older versions. If no matching binding is found the server is left unchanged and the method returns False.

Example

if not oServer.RemoveBinding('0.0.0.0', 5000) then
  ShowMessage('Binding not found');

Back to Methods