WebSocket QML Type

QML 接口到 QWebSocket . 更多...

import 語句: import QtWebSockets 1.10

特性

信號

方法

詳細描述

WebSocket 是通過單 TCP 連接提供全雙工通信通道的 Web 技術。WebSocket 協議由 IETF 標準化為 RFC 6455 in 2011.

特性文檔編製

active : bool

When set to true, a connection is made to the server with the given url. When set to false, the connection is closed. The default value is false.

errorString : string [read-only]

Contains a description of the last error that occurred. When no error occurrred, this string is empty.

negotiatedSubprotocol : string [read-only, since 6.4]

The WebSocket subprotocol that has been negotiated with the server.

該特性在 Qt 6.4 引入。

requestedSubprotocols : list < string > [since 6.4]

The list of WebSocket subprotocols to send in the WebSocket handshake.

該特性在 Qt 6.4 引入。

status : Status [read-only]

Status of the WebSocket.

The status can have the following values:

  • WebSocket.Connecting
  • WebSocket.Open
  • WebSocket.Closing
  • WebSocket.Closed
  • WebSocket.Error

url : url

Server url to connect to. The url must have one of 2 schemes: ws:// or wss:// . When not supplied, then ws:// 被使用。

信號文檔編製

binaryMessageReceived ( QString message )

This signal is emitted when a binary message is received. message contains the bytes received.

注意: 相應處理程序是 onBinaryMessageReceived .

[since 6.10] pong ( quint64 elapsedTime , ArrayBuffer payload )

發射當收到先前 Ping (乒) 迴復的 pong (乓) 消息時。 elapsedTime 包含往返時間 (以毫秒為單位) 而 payload 包含與 Ping (乒) 一起發送的可選負載。

注意: 相應處理程序是 onPong .

This signal was introduced in Qt 6.10.

另請參閱 ping ().

statusChanged ( Status status )

This signal is emitted when the status of the WebSocket changes. The status argument provides the current status.

注意: 相應處理程序是 onStatusChanged .

另請參閱 WebSocket::status .

textMessageReceived ( QString message )

This signal is emitted when a text message is received. message contains the bytes received.

注意: 相應處理程序是 onTextMessageReceived .

方法文檔編製

[since 6.10] void ping ()

[since 6.10] void ping ( ArrayBuffer payload )

Ping (乒) 服務器以指示連接仍活著。額外 payload 可以沿 Ping (乒) 消息一起發送。

大小對於 payload 不能大於 125 字節。若更大, payload 被裁剪到 125 字節。

注意: QWebSocket and QWebSocketServer 在內部處理 Ping (乒) 請求,意味著它們會自動發送迴對等方的 Pong (乓) 響應。

These methods were introduced in Qt 6.10.

另請參閱 pong ().

void sendBinaryMessage ( ArrayBuffer message )

Sends the parameter message to the server.

void sendTextMessage ( string message )

發送 message to the server.