TsgcUDPServer › Methods › AddBinding
Adds a new listening endpoint (IP/port) to the server without restarting the currently active bindings.
function AddBinding(const aIPAddress: string; aPort: Integer; const aName: string = ''): TIdSocketHandle;
| Name | Type | Description |
|---|---|---|
aIPAddress | const string | Local IPv4/IPv6 address to bind to. Use an empty string, 0.0.0.0 or :: to bind every interface. |
aPort | Integer | Local UDP port number (1 to 65535). Use 0 to request an ephemeral port from the OS. |
aName | const string | Optional friendly name used by the custom Indy build to label the listener thread; pass an empty string to accept the default. |
The newly created TIdSocketHandle (or the existing one if an entry for aIPAddress/aPort already exists). The handle is owned by the Bindings collection and must not be freed by the caller. (TIdSocketHandle)
AddBinding adds a new entry to Bindings, allocates its datagram socket, binds the socket and spawns the listener thread without stopping any other binding already served by the component. This allows the server to start listening on an additional IP/port at runtime (for example to bring up both IPv4 and IPv6 endpoints, or to add a new interface when it becomes available). If a binding with the same IP and port already exists it is returned unchanged and no new socket is opened. The method requires Indy 10.2 or later and raises an exception on older versions.
oServer.AddBinding('0.0.0.0', 5000);
oServer.AddBinding('::', 5000);