openharmony 鸿蒙 capi-net-websocket-type-h

2026-08-25 浏览 (1)

net_websocket_type.h

Overview

Defines data structures for the C APIs of the WebSocket client module.

File to include: <network/netstack/net_websocket_type.h>

Library: libnet_websocket.so

System capability: SystemCapability.Communication.NetStack

Since: 11

Related module: netstack

Summary

Structs

NameDescription
WebSocket_CloseResultParameters for the Close message sent from the WebSocket server to client.
WebSocket_CloseOptionParameters for the connection closure initiated by the WebSocket client.
WebSocket_ErrorResultParameters for the Error message sent from the WebSocket server to client.
WebSocket_OpenResultParameters for the Open message sent from the WebSocket server to client.
WebSocket_HeaderHeader linked list added to the WebSocket client.
WebSocket_RequestOptionsParameters of the request for connection between the WebSocket client and server.
WebSocketWebSocket client structure.

Functions

Nametypedef KeywordDescription
typedef void (*WebSocket_OnOpenCallback)(struct WebSocket *client, WebSocket_OpenResult openResult)WebSocket_OnOpenCallbackCallback invoked when the WebSocket client receives an Open message.
typedef void (*WebSocket_OnMessageCallback)(struct WebSocket *client, char *data, uint32_t length)WebSocket_OnMessageCallbackCallback invoked when the WebSocket client receives data.
typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_ErrorResult errorResult)WebSocket_OnErrorCallbackCallback invoked when the WebSocket client receives an Error message.
typedef void (*WebSocket_OnCloseCallback)(struct WebSocket *client, WebSocket_CloseResult closeResult)WebSocket_OnCloseCallbackCallback invoked when the WebSocket client receives a Close message.

Enum Description

WebSocket_ErrCode

enum WebSocket_ErrCode

Description

Defines the error codes of a WebSocket request.

Since: 11

ValueDescription
WEBSOCKET_OK = 0Operation successful.
E_BASE = 1000Base value of the error code.
WEBSOCKET_CLIENT_NULL = (E_BASE + 1)The WebSocket client is empty.
WEBSOCKET_CLIENT_NOT_CREATED = (E_BASE + 2)The WebSocket client is not created.
WEBSOCKET_CONNECTION_ERROR = (E_BASE + 3)An error occurred during WebSocket connection establishment.
WEBSOCKET_CONNECTION_PARSE_URL_ERROR = (E_BASE + 5)An error occurred when parsing WebSocket connection parameters.
WEBSOCKET_CONNECTION_NO_MEMORY = (E_BASE + 6)The memory is insufficient during WebSocket client connection establishment.
WEBSOCKET_CONNECTION_CLOSED_BY_PEER = (E_BASE + 7)The WebSocket connection is closed by the peer end.
WEBSOCKET_DESTROYED = (E_BASE + 8)The WebSocket connection is disconnected.
WEBSOCKET_PROTOCOL_ERROR = (E_BASE + 9)Incorrect protocol.
WEBSOCKET_SEND_NO_MEMORY = (E_BASE + 10)The system memory is insufficient when the WebSocket client sends data.
WEBSOCKET_SEND_DATA_NULL = (E_BASE + 11)The sent data is empty.
WEBSOCKET_DATA_LENGTH_EXCEEDED = (E_BASE + 12)The length of the sent data exceeds the limit.
WEBSOCKET_QUEUE_LENGTH_EXCEEDED = (E_BASE + 13)The length of the sent data queue exceeds the limit.
WEBSOCKET_NO_CLIENT_CONTEXT = (E_BASE + 14)The context of the WebSocket client is null.
WEBSOCKET_NO_HEADER_CONTEXT = (E_BASE + 15)The protocol header of the WebSocket client is empty.
WEBSOCKET_HEADER_EXCEEDED = (E_BASE + 16)The protocol header of the WebSocket client exceeds the limit.
WEBSOCKET_NO_CONNECTION = (E_BASE + 17)The WebSocket client is not connected.
WEBSOCKET_NO_CONNECTION_CONTEXT = (E_BASE + 18)No WebSocket connection context is released.

Function Description

WebSocket_OnOpenCallback()

typedef void (*WebSocket_OnOpenCallback)(struct WebSocket *client, WebSocket_OpenResult openResult)

Description

Callback invoked when the WebSocket client receives an Open message.

Since: 11

Parameters

NameDescription
struct WebSocket *clientWebSocket client.
WebSocket_OpenResult openResultContent of the Open message sent from the WebSocket server to client.

WebSocket_OnMessageCallback()

typedef void (*WebSocket_OnMessageCallback)(struct WebSocket *client, char *data, uint32_t length)

Description

Callback invoked when the WebSocket client receives a Message message.

Since: 11

Parameters

NameDescription
struct WebSocket *clientWebSocket client.
char *dataData received by the WebSocket client.
uint32_t lengthLength of the data received by the WebSocket client.

WebSocket_OnErrorCallback()

typedef void (*WebSocket_OnErrorCallback)(struct WebSocket *client, WebSocket_ErrorResult errorResult)

Description

Callback invoked when the WebSocket client receives an Error message.

Since: 11

Parameters

NameDescription
struct WebSocket *clientWebSocket client.
WebSocket_ErrorResult errorResultContent of the Error message sent from the WebSocket server to client.

WebSocket_OnCloseCallback()

typedef void (*WebSocket_OnCloseCallback)(struct WebSocket *client, WebSocket_CloseResult closeResult)

Description

Callback invoked when the WebSocket client receives a Close message.

Since: 11

Parameters

NameDescription
struct WebSocket *clientWebSocket client.
WebSocket_CloseResult closeResultContent of the Close message sent from the WebSocket server to client.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-netconnection-netconn-connectionproperties

openharmony 鸿蒙 errorcode-net-mdns

openharmony 鸿蒙 js-apis-net-ethernet-sys

openharmony 鸿蒙 errorcode-net-http

openharmony 鸿蒙 capi-netstack-http-proxy

openharmony 鸿蒙 js-apis-system-fetch

openharmony 鸿蒙 errorcode-kernel

openharmony 鸿蒙 capi-netstack-netstack-certblob

openharmony 鸿蒙 js-apis-net-mdns

openharmony 鸿蒙 capi-netstack-websocket-closeoption

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/BJKXdA2V