TsgcIWWebSocketClient

TsgcIWWebSocketClient implements Intraweb WebSocket Component and can connect to a WebSocket Server. Follow the steps below to configure this component:

 

1. Drop a TsgcIWWebSocketClient component in the form

 

2. Set Host and Port (default is 80) to connect to an available WebSocket Server. You can set URL property and Host, Port, Parameters... will be updated from URL. Example: wss://127.0.0.1:8080/ws/ will result:

 


oClient := TsgcIWWebSocketClient.Create(nil);
oClient.Host := '127.0.0.1';
oClient.Port := 80;
oClient.TLS := True;
oClient.Options.Parameters := '/ws/';

 

3. You can select if you want TLS (secure connection) or not, by default is not Activated.

 

4. Set Transports allowed.

 

    WebSockets: it will use standard WebSocket implementation

 

    Emulation: if browser doesn't support WebSockets, then it will use a loop AJAX callback connection

 

5. If you want, you can handle events

 

    OnAsyncConnect: when a WebSocket connection is established, this event is triggered

 

    OnAsyncDisconnect: when a WebSocket connection is dropped, this event is triggered

 

    OnAsyncError: every time there is a WebSocket error (like mal-formed handshake), this event is triggered

 

    OnAsyncMessage: every time the server sends a message, this event is triggered

 

    OnAsyncEmulation: this event is fired on every loop of emulated connection

 

6. Create an Async Procedure and set property Active := True

 

 

Methods

 

    Open: Opens a WebSocket Connection.

 

    Close: Closes a WebSocket Connection.

 

    WriteData: sends a message to WebSocket Server.

 

 

Properties

 

   Connected: is a read-only variable and returns True if the connection is Active, otherwise returns False.

 

    JSOpen: here you can include JavaScript Code on the client side when a connection is opened.

 

    JSClose: here you can include JavaScript Code on the client side when a connection is closed.

 

    JSMessage: here you can include JavaScript Code on the client side when clients receive a message from the server. You can get Message String, using Javascript variable "text".

 

    JSError: here you can include JavaScript Code on the client side when an error is raised. You can get Message Error, using Javascript variable "text".