client
pub fn client(endpoint string) WsClientPurpose
client; returns WsClient.
Parameters
endpointstring- endpoint (string)
Returns
WsClient — a value of this type
API
#github.com/xulang-org/packages/websocketExternal package `websocket #github.com/xulang-org/packages/websocket`, provided by github.com/xulang-org/packages.
github.com/xulang-org/packages · 0.1.1 · Install and use
clientpub fn client(endpoint string) WsClientclient; returns WsClient.
endpoint stringWsClient — a value of this type
poolpub fn pool(endpoint string, max_conns int) WsPoolpool; returns WsPool.
endpoint stringmax_conns intWsPool — a value of this type
struct WsClientpub struct WsClient {
pub host string
pub port int
pub path string
}Public struct `WsClient`.
host stringport intpath stringnew_clientpub fn new_client(endpoint string) WsClientConstruct client.
endpoint stringWsClient — a value of this type
(WsClient) connectpub fn (c WsClient) connect() intCall `connect` on `WsClient`. Throws on failure.
c WsClientint — a value of this type
(WsClient) send_textpub fn (c WsClient) send_text(fd int, text string) boolMethod on `WsClient`: send text.
c WsClientfd inttext stringbool — true or false
(WsClient) send_binarypub fn (c WsClient) send_binary(fd int, data string) boolMethod on `WsClient`: send binary.
c WsClientfd intdata stringbool — true or false
(WsClient) send_pingpub fn (c WsClient) send_ping(fd int, payload string) boolMethod on `WsClient`: send ping.
c WsClientfd intpayload stringbool — true or false
(WsClient) send_pongpub fn (c WsClient) send_pong(fd int, payload string) boolMethod on `WsClient`: send pong.
c WsClientfd intpayload stringbool — true or false
(WsClient) close_connpub fn (c WsClient) close_conn(fd int)Method on `WsClient`: close connection.
c WsClientfd int(WsClient) read_framepub fn (c WsClient) read_frame(fd int) FrameMethod on `WsClient`: read frame. Throws on failure.
c WsClientfd intFrame — a value of this type
(WsClient) read_textpub fn (c WsClient) read_text(fd int) stringMethod on `WsClient`: read text. Throws on failure.
c WsClientfd intstring — result string
const opcode_continuationpub const opcode_continuation = 0Public constant `opcode_continuation`. Value `0`.
none
const opcode_textpub const opcode_text = 1Public constant `opcode_text`. Value `1`.
none
const opcode_binarypub const opcode_binary = 2Public constant `opcode_binary`. Value `2`.
none
const opcode_closepub const opcode_close = 8Public constant `opcode_close`. Value `8`.
none
const opcode_pingpub const opcode_ping = 9Public constant `opcode_ping`. Value `9`.
none
const opcode_pongpub const opcode_pong = 10Public constant `opcode_pong`. Value `10`.
none
struct Framepub struct Frame {
pub fin bool
pub opcode int
pub masked bool
pub payload string
}Public struct `Frame`.
fin boolopcode intmasked boolpayload stringbuild_framepub fn build_frame(opcode int, payload string, fin bool, mask bool) stringBuilds a WebSocket frame according to RFC 6455
opcode intpayload stringfin boolmask boolstring — result string
apply_maskpub fn apply_mask(payload string, m0 int, m1 int, m2 int, m3 int) stringUnmasks or masks payload given 4-byte mask
payload stringm0 intm1 intm2 intm3 intstring — result string
compute_accept_keypub fn compute_accept_key(sec_key string) stringCompute accept key.
sec_key stringstring — result string
build_handshake_requestpub fn build_handshake_request(host string, port int, path string, sec_key string) stringBuild handshake request.
host stringport intpath stringsec_key stringstring — result string
struct HandshakeResultpub struct HandshakeResult {
pub status_code int
pub accept_key string
}Public struct `HandshakeResult`.
status_code intaccept_key stringparse_handshake_responsepub fn parse_handshake_response(resp string) HandshakeResultParse as handshake response.
resp stringHandshakeResult — a value of this type
struct WsPoolpub struct WsPool {
pub client WsClient
pub idle chan int
pub max_idle int
}Public struct `WsPool`.
client WsClientidle chan intmax_idle intopen_poolpub fn open_pool(endpoint string, max_idle int) WsPoolOpen pool.
endpoint stringmax_idle intWsPool — a value of this type
(&WsPool) get_connpub fn (p &WsPool) get_conn() intMethod on `&WsPool`: read conn.
p &WsPoolint — a value of this type
(&WsPool) put_connpub fn (p &WsPool) put_conn(fd int)Method on `&WsPool`: put connection.
p &WsPoolfd int(&WsPool) echo_textpub fn (p &WsPool) echo_text(text string) stringExecutes an echo round-trip borrowing from pool Throws on failure.
p &WsPooltext stringstring — result string
(&WsPool) closepub fn (p &WsPool) close()Method on `&WsPool`: close the resource.
p &WsPool