TsgcWebSocketServer | Server Bindings

By default, if you only fill Port property, server binds listening port of ALL IPs, so if for example, you have 3 IP: 127.0.0.1, 80.5411.22 and 12.55.41.17. Your server will bind this port on 3 IPs.

Usually is recommended only binding to needed IPs, here is where you can user Bindings property.

Instead of use Port property, just use Binding property and fill with IP and Port required.

 

Example: bind Port 5555 to IP 127.0.0.1 and IP 80.58.25.40

 


oServer := TsgcWebSocketServer.Create(nil);
With oServer.Bindings.Add do
begin
  IP := '127.0.0.1';
  Port := 5555;
end;
With oServer.Bindings.Add do
begin
  IP := '80.58.25.40';
  Port := 5555;
end;
oServer.Active := true;

 

If you change the Port after closing a server, to start listening on a different port, call the method Bindings.Clear() after closing the server to delete all previous bindings. Otherwise the server will try to bind to the previous bindings.