XU XUv0.8.8
EN

API

#github.com/xulang-org/packages/websocket

import: websocket #github.com/xulang-org/packages/websocket

counts: 9 函数, 12 方法, 4 类型, 6 常量, 0 方法集

扩展包 `websocket #github.com/xulang-org/packages/websocket`,由模块 github.com/xulang-org/packages 提供。

github.com/xulang-org/packages · 0.1.1 · 安装与使用

client

XuAPI
pub fn client(endpoint string) WsClient

用途

客户端。

参数

endpoint string
endpoint(string)

返回

WsClient — 该类型的值

pool

XuAPI
pub fn pool(endpoint string, max_conns int) WsPool

用途

pool,返回 WsPool。

参数

endpoint string
endpoint(string)
max_conns int
max_conns(int)

返回

WsPool — 该类型的值

struct WsClient

XuAPI
pub struct WsClient {
    pub host string
    pub port int
    pub path string
}

用途

公开结构体 `WsClient`。

参数

host string
主机
port int
端口
path string
文件系统路径

new_client

XuAPI
pub fn new_client(endpoint string) WsClient

用途

构造 client。

参数

endpoint string
endpoint(string)

返回

WsClient — 该类型的值

(WsClient) connect

XuAPI
pub fn (c WsClient) connect() int

用途

在 `WsClient` 上调用 `connect`。失败时 throw。

参数

c WsClient
接收者 WsClient(值接收者)

返回

int — 该类型的值

(WsClient) send_text

XuAPI
pub fn (c WsClient) send_text(fd int, text string) bool

用途

`WsClient` 上的方法:send文本。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)
text string
文本(string)

返回

bool — 是否成立

(WsClient) send_binary

XuAPI
pub fn (c WsClient) send_binary(fd int, data string) bool

用途

`WsClient` 上的方法:sendbinary。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)
data string
数据(string)

返回

bool — 是否成立

(WsClient) send_ping

XuAPI
pub fn (c WsClient) send_ping(fd int, payload string) bool

用途

`WsClient` 上的方法:sendping。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)
payload string
payload(string)

返回

bool — 是否成立

(WsClient) send_pong

XuAPI
pub fn (c WsClient) send_pong(fd int, payload string) bool

用途

`WsClient` 上的方法:sendpong。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)
payload string
payload(string)

返回

bool — 是否成立

(WsClient) close_conn

XuAPI
pub fn (c WsClient) close_conn(fd int)

用途

`WsClient` 上的方法:关闭连接。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)

(WsClient) read_frame

XuAPI
pub fn (c WsClient) read_frame(fd int) Frame

用途

`WsClient` 上的方法:读取frame。失败时 throw。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)

返回

Frame — 该类型的值

(WsClient) read_text

XuAPI
pub fn (c WsClient) read_text(fd int) string

用途

`WsClient` 上的方法:读取文本。失败时 throw。

参数

c WsClient
接收者 WsClient(值接收者)
fd int
文件描述符(int)

返回

string — 结果字符串

const opcode_continuation

XuAPI
pub const opcode_continuation = 0

用途

公开常量 `opcode_continuation`。 值为 `0`

参数

无

const opcode_text

XuAPI
pub const opcode_text = 1

用途

公开常量 `opcode_text`。 值为 `1`

参数

无

const opcode_binary

XuAPI
pub const opcode_binary = 2

用途

公开常量 `opcode_binary`。 值为 `2`

参数

无

const opcode_close

XuAPI
pub const opcode_close = 8

用途

公开常量 `opcode_close`。 值为 `8`

参数

无

const opcode_ping

XuAPI
pub const opcode_ping = 9

用途

公开常量 `opcode_ping`。 值为 `9`

参数

无

const opcode_pong

XuAPI
pub const opcode_pong = 10

用途

公开常量 `opcode_pong`。 值为 `10`

参数

无

struct Frame

XuAPI
pub struct Frame {
    pub fin bool
    pub opcode int
    pub masked bool
    pub payload string
}

用途

公开结构体 `Frame`。

参数

fin bool
字段(bool)
opcode int
字段(int)
masked bool
字段(bool)
payload string
字段(string)

build_frame

XuAPI
pub fn build_frame(opcode int, payload string, fin bool, mask bool) string

用途

buildframe。

参数

opcode int
opcode(int)
payload string
payload(string)
fin bool
fin(bool)
mask bool
mask(bool)

返回

string — 结果字符串

apply_mask

XuAPI
pub fn apply_mask(payload string, m0 int, m1 int, m2 int, m3 int) string

用途

applymask。

参数

payload string
payload(string)
m0 int
m0(int)
m1 int
m1(int)
m2 int
m2(int)
m3 int
m3(int)

返回

string — 结果字符串

compute_accept_key

XuAPI
pub fn compute_accept_key(sec_key string) string

用途

compute接受键。

参数

sec_key string
sec_key(string)

返回

string — 结果字符串

build_handshake_request

XuAPI
pub fn build_handshake_request(host string, port int, path string, sec_key string) string

用途

buildhandshake请求。

参数

host string
主机(string)
port int
端口(int)
path string
文件系统路径(string)
sec_key string
sec_key(string)

返回

string — 结果字符串

struct HandshakeResult

XuAPI
pub struct HandshakeResult {
    pub status_code int
    pub accept_key string
}

用途

公开结构体 `HandshakeResult`。

参数

status_code int
字段(int)
accept_key string
字段(string)

parse_handshake_response

XuAPI
pub fn parse_handshake_response(resp string) HandshakeResult

用途

解析为 handshake response。

参数

resp string
resp(string)

返回

HandshakeResult — 该类型的值

struct WsPool

XuAPI
pub struct WsPool {
    pub client WsClient
    pub idle chan int
    pub max_idle int
}

用途

公开结构体 `WsPool`。

参数

client WsClient
字段(WsClient)
idle chan int
字段(通道;类型 chan int)
max_idle int
字段(int)

open_pool

XuAPI
pub fn open_pool(endpoint string, max_idle int) WsPool

用途

打开pool。

参数

endpoint string
endpoint(string)
max_idle int
max_idle(int)

返回

WsPool — 该类型的值

(&WsPool) get_conn

XuAPI
pub fn (p &WsPool) get_conn() int

用途

`&WsPool` 上的方法:读取 conn。

参数

p &WsPool
接收者 &WsPool(借用)

返回

int — 该类型的值

(&WsPool) put_conn

XuAPI
pub fn (p &WsPool) put_conn(fd int)

用途

`&WsPool` 上的方法:put连接。

参数

p &WsPool
接收者 &WsPool(借用)
fd int
文件描述符(int)

(&WsPool) echo_text

XuAPI
pub fn (p &WsPool) echo_text(text string) string

用途

`&WsPool` 上的方法:echo文本。失败时 throw。

参数

p &WsPool
接收者 &WsPool(借用)
text string
文本(string)

返回

string — 结果字符串

(&WsPool) close

XuAPI
pub fn (p &WsPool) close()

用途

`&WsPool` 上的方法:关闭资源。

参数

p &WsPool
接收者 &WsPool(借用)