WebSocket Object

The WebSocket object implements text-based communication with a server via the WebSocket protocol. Its functions block until completion for convenient use within a test script.

var socket;
try {
    socket = WebSocket.connect("websocket-server", 80);
} catch (e) {
    test.log("Could not connect: " + e);
    return;
}

socket.timeout = 500;
socket.sendTextMessage( "'Quack!' said the frog." );
test.log("received: " + socket.receiveTextMessage());
socket.close();

WebSocket WebSocket.connect( hostname)

Connects to hostname:port and returns a WebSocket object on success. On failure, an exception is thrown.

websocket.close()

Closes a WebSocket connection.

websocket.sendTextMessage( message)

Sends a text message through the WebSocket. Throws an exception on failure.

String websocket.receiveTextMessage()

Receives a message from the WebSocket. Throws an exception if there is nothing to receive.

String websocket.host

A readonly property that holds the host this socket is connected to.

Boolean websocket.open

A readonly property that tells if this socket is currently open.

Number websocket.port

A readonly property that holds the port this socket is connected to.

Number websocket.timeout

Holds the timeout (default: 3000 ms) used when sending and receiving data through the WebSocket. This property can be changed at any time and expects a millisecond value.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

Search Results