TsgcWebSocketServer | Start Server

The first you must set when you want start a Server is set a Listening Port, by default, this is set to port 80 but you can change for any port.

Once the port is set, there are 2 methods to start a server.

 

Active Property

If you set Active property to true, server will start to listening all incoming connection on port set.


oServer := TsgcWebSocketServer.Create(nil);
oServer.Port := 80;
oServer.Active := true;

If you set Active property to false, server will stop and close all active connections.

 


oServer.Active := false;

 

Start / Stop methods

 

While if you call Active property the process of start / stop server is done in the same thread, calling Start and Stop methods will be executed in a secondary thread.

 


oServer := TsgcWebSocketServer.Create(nil);
oServer.Port := 80;
oServer.Start();

If you call Stop() method, server will stop and close all active connections.

 


oServer.Stop();

You can use the method ReStart, to Stop and Start server in a secondary thread.

 

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.