WebSocket Parameters Connection

Supported by

 

  TsgcWebSocketClient

  Java script

 

Sometimes is useful to pass parameters from client to server when a new WebSocket the connection is established. If you need to pass some parameters to the server, you can use the following property:

 

  Options / Parameters

 

By default, is set to '/', if you need to pass a parameter like id=1, you can set this property to '/?id=1'

 

On Server Side, you can handle client parameters using the following parameter:


procedure WSServerConnect(Connection: TsgcWSConnection);
begin
  if Connection.URL = '/?id=1' then
    HandleThisParameter;
end;

 

Using Javascript, you can pass parameters using connection url, example:

 


<script src="http://localhost/sgcWebSockets.js" type="text/javascript"></script>
<script type="text/javascript">var socket = new sgcWebSocket('ws://localhost/?id=1');</script>