WebSocketSendTextMessage Function

Action

Sends a text message to the WebSocket server. The function does not wait for a response. Note: A WebSocket is an asynchronous communication channel, which is not bound to the conventional request-response pattern. Both the client and the server can send messages at any time.

Include file

webapi.bdh

Syntax

WebSocketSendTextMessage( in hWebSocket       : number,
                          in sData            : dstring,
                          in nMaxFragmentSize : number optional ): boolean
Parameter Description
hWebSocket A handle, which identifies the WebSocket. To retrieve this handle, use the WebSocketConnect() function.
sData The content of the message to be sent to the server.
nMaxFragmentSize Large messages can be split up into smaller parts or fragments by the client. This parameter specifies the maximum size of one fragment.

Return value

  • true if successful

  • false otherwise

Example

 transaction TMain
  var
    hWebSocket : number;
  begin
    hWebSocket := WebSocketConnect("http://echo.websocket.org", callback(FWebSocketMessageReceived));
    
    WebSocketSendTextMessage(hWebSocket, "Rock it with HTML5 WebSocket");
 
    Print("Waiting...");
    Wait(4.1);
    
    WebSocketSendTextMessage(hWebSocket, "Hello World!");

    Print("Waiting...");
    Wait(3.6);
    
    WebSocketSendTextMessage(hWebSocket, "Bye");
    WebSocketClose(hWebSocket);
  end TMain;