client
pub fn client(endpoint string) WsClient用途
客户端。
参数
endpointstring- endpoint(string)
返回
WsClient — 该类型的值
API
#github.com/xulang-org/packages/websocket扩展包 `websocket #github.com/xulang-org/packages/websocket`,由模块 github.com/xulang-org/packages 提供。
github.com/xulang-org/packages · 0.1.1 · 安装与使用
clientpub fn client(endpoint string) WsClient客户端。
endpoint stringWsClient — 该类型的值
poolpub fn pool(endpoint string, max_conns int) WsPoolpool,返回 WsPool。
endpoint stringmax_conns intWsPool — 该类型的值
struct WsClientpub struct WsClient {
pub host string
pub port int
pub path string
}公开结构体 `WsClient`。
host stringport intpath stringnew_clientpub fn new_client(endpoint string) WsClient构造 client。
endpoint stringWsClient — 该类型的值
(WsClient) connectpub fn (c WsClient) connect() int在 `WsClient` 上调用 `connect`。失败时 throw。
c WsClientint — 该类型的值
(WsClient) send_textpub fn (c WsClient) send_text(fd int, text string) bool`WsClient` 上的方法:send文本。
c WsClientfd inttext stringbool — 是否成立
(WsClient) send_binarypub fn (c WsClient) send_binary(fd int, data string) bool`WsClient` 上的方法:sendbinary。
c WsClientfd intdata stringbool — 是否成立
(WsClient) send_pingpub fn (c WsClient) send_ping(fd int, payload string) bool`WsClient` 上的方法:sendping。
c WsClientfd intpayload stringbool — 是否成立
(WsClient) send_pongpub fn (c WsClient) send_pong(fd int, payload string) bool`WsClient` 上的方法:sendpong。
c WsClientfd intpayload stringbool — 是否成立
(WsClient) close_connpub fn (c WsClient) close_conn(fd int)`WsClient` 上的方法:关闭连接。
c WsClientfd int(WsClient) read_framepub fn (c WsClient) read_frame(fd int) Frame`WsClient` 上的方法:读取frame。失败时 throw。
c WsClientfd intFrame — 该类型的值
(WsClient) read_textpub fn (c WsClient) read_text(fd int) string`WsClient` 上的方法:读取文本。失败时 throw。
c WsClientfd intstring — 结果字符串
const opcode_continuationpub const opcode_continuation = 0公开常量 `opcode_continuation`。 值为 `0`
无
const opcode_textpub const opcode_text = 1公开常量 `opcode_text`。 值为 `1`
无
const opcode_binarypub const opcode_binary = 2公开常量 `opcode_binary`。 值为 `2`
无
const opcode_closepub const opcode_close = 8公开常量 `opcode_close`。 值为 `8`
无
const opcode_pingpub const opcode_ping = 9公开常量 `opcode_ping`。 值为 `9`
无
const opcode_pongpub const opcode_pong = 10公开常量 `opcode_pong`。 值为 `10`
无
struct Framepub struct Frame {
pub fin bool
pub opcode int
pub masked bool
pub payload string
}公开结构体 `Frame`。
fin boolopcode intmasked boolpayload stringbuild_framepub fn build_frame(opcode int, payload string, fin bool, mask bool) stringbuildframe。
opcode intpayload stringfin boolmask boolstring — 结果字符串
apply_maskpub fn apply_mask(payload string, m0 int, m1 int, m2 int, m3 int) stringapplymask。
payload stringm0 intm1 intm2 intm3 intstring — 结果字符串
compute_accept_keypub fn compute_accept_key(sec_key string) stringcompute接受键。
sec_key stringstring — 结果字符串
build_handshake_requestpub fn build_handshake_request(host string, port int, path string, sec_key string) stringbuildhandshake请求。
host stringport intpath stringsec_key stringstring — 结果字符串
struct HandshakeResultpub struct HandshakeResult {
pub status_code int
pub accept_key string
}公开结构体 `HandshakeResult`。
status_code intaccept_key stringparse_handshake_responsepub fn parse_handshake_response(resp string) HandshakeResult解析为 handshake response。
resp stringHandshakeResult — 该类型的值
struct WsPoolpub struct WsPool {
pub client WsClient
pub idle chan int
pub max_idle int
}公开结构体 `WsPool`。
client WsClientidle chan intmax_idle intopen_poolpub fn open_pool(endpoint string, max_idle int) WsPool打开pool。
endpoint stringmax_idle intWsPool — 该类型的值
(&WsPool) get_connpub fn (p &WsPool) get_conn() int`&WsPool` 上的方法:读取 conn。
p &WsPoolint — 该类型的值
(&WsPool) put_connpub fn (p &WsPool) put_conn(fd int)`&WsPool` 上的方法:put连接。
p &WsPoolfd int(&WsPool) echo_textpub fn (p &WsPool) echo_text(text string) string`&WsPool` 上的方法:echo文本。失败时 throw。
p &WsPooltext stringstring — 结果字符串
(&WsPool) closepub fn (p &WsPool) close()`&WsPool` 上的方法:关闭资源。
p &WsPool