XU XUv0.8.8
中文

API

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

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

counts: 9 fns, 12 methods, 4 types, 6 consts, 0 ifaces

External 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

client

XuAPI
pub fn client(endpoint string) WsClient

Purpose

client; returns WsClient.

Parameters

endpoint string
endpoint (string)

Returns

WsClient — a value of this type

pool

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

Purpose

pool; returns WsPool.

Parameters

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

Returns

WsPool — a value of this type

struct WsClient

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

Purpose

Public struct `WsClient`.

Parameters

host string
host
port int
port
path string
filesystem path

new_client

XuAPI
pub fn new_client(endpoint string) WsClient

Purpose

Construct client.

Parameters

endpoint string
endpoint (string)

Returns

WsClient — a value of this type

(WsClient) connect

XuAPI
pub fn (c WsClient) connect() int

Purpose

Call `connect` on `WsClient`. Throws on failure.

Parameters

c WsClient
receiver WsClient (value receiver)

Returns

int — a value of this type

(WsClient) send_text

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

Purpose

Method on `WsClient`: send text.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)
text string
text (string)

Returns

bool — true or false

(WsClient) send_binary

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

Purpose

Method on `WsClient`: send binary.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)
data string
data (string)

Returns

bool — true or false

(WsClient) send_ping

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

Purpose

Method on `WsClient`: send ping.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)
payload string
payload (string)

Returns

bool — true or false

(WsClient) send_pong

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

Purpose

Method on `WsClient`: send pong.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)
payload string
payload (string)

Returns

bool — true or false

(WsClient) close_conn

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

Purpose

Method on `WsClient`: close connection.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)

(WsClient) read_frame

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

Purpose

Method on `WsClient`: read frame. Throws on failure.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)

Returns

Frame — a value of this type

(WsClient) read_text

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

Purpose

Method on `WsClient`: read text. Throws on failure.

Parameters

c WsClient
receiver WsClient (value receiver)
fd int
file descriptor (int)

Returns

string — result string

const opcode_continuation

XuAPI
pub const opcode_continuation = 0

Purpose

Public constant `opcode_continuation`. Value `0`.

Parameters

none

const opcode_text

XuAPI
pub const opcode_text = 1

Purpose

Public constant `opcode_text`. Value `1`.

Parameters

none

const opcode_binary

XuAPI
pub const opcode_binary = 2

Purpose

Public constant `opcode_binary`. Value `2`.

Parameters

none

const opcode_close

XuAPI
pub const opcode_close = 8

Purpose

Public constant `opcode_close`. Value `8`.

Parameters

none

const opcode_ping

XuAPI
pub const opcode_ping = 9

Purpose

Public constant `opcode_ping`. Value `9`.

Parameters

none

const opcode_pong

XuAPI
pub const opcode_pong = 10

Purpose

Public constant `opcode_pong`. Value `10`.

Parameters

none

struct Frame

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

Purpose

Public struct `Frame`.

Parameters

fin bool
field (bool)
opcode int
field (int)
masked bool
field (bool)
payload string
field (string)

build_frame

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

Purpose

Builds a WebSocket frame according to RFC 6455

Parameters

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

Returns

string — result string

apply_mask

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

Purpose

Unmasks or masks payload given 4-byte mask

Parameters

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

Returns

string — result string

compute_accept_key

XuAPI
pub fn compute_accept_key(sec_key string) string

Purpose

Compute accept key.

Parameters

sec_key string
sec_key (string)

Returns

string — result string

build_handshake_request

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

Purpose

Build handshake request.

Parameters

host string
host (string)
port int
port (int)
path string
filesystem path (string)
sec_key string
sec_key (string)

Returns

string — result string

struct HandshakeResult

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

Purpose

Public struct `HandshakeResult`.

Parameters

status_code int
field (int)
accept_key string
field (string)

parse_handshake_response

XuAPI
pub fn parse_handshake_response(resp string) HandshakeResult

Purpose

Parse as handshake response.

Parameters

resp string
resp (string)

Returns

HandshakeResult — a value of this type

struct WsPool

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

Purpose

Public struct `WsPool`.

Parameters

client WsClient
field (WsClient)
idle chan int
field (channel; type chan int)
max_idle int
field (int)

open_pool

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

Purpose

Open pool.

Parameters

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

Returns

WsPool — a value of this type

(&WsPool) get_conn

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

Purpose

Method on `&WsPool`: read conn.

Parameters

p &WsPool
receiver &WsPool (borrow)

Returns

int — a value of this type

(&WsPool) put_conn

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

Purpose

Method on `&WsPool`: put connection.

Parameters

p &WsPool
receiver &WsPool (borrow)
fd int
file descriptor (int)

(&WsPool) echo_text

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

Purpose

Executes an echo round-trip borrowing from pool Throws on failure.

Parameters

p &WsPool
receiver &WsPool (borrow)
text string
text (string)

Returns

string — result string

(&WsPool) close

XuAPI
pub fn (p &WsPool) close()

Purpose

Method on `&WsPool`: close the resource.

Parameters

p &WsPool
receiver &WsPool (borrow)