websocket
Generated by tinox doc
RFC 6455 WebSocket server (WsServer/Ws) and client (WsClient), built on the HTTP server's raw connection-handle layer. v1 is an explicit accept/read-loop API (no lambda handler), serving one connection at a time; Ws::readMessage handles ping/pong/close automatically. TLS variants (wss://) are available via WsServer::listenTls/acceptTls.
| Module | Version | Group |
|---|---|---|
base64 | 1.0.0 | tinox.core |
socket | 1.0.0 | tinox.core |
Echo server
import tinox.core.websocket;
class Main
{
fnc main() -> Int32
{
let srv: Int64 = WsServer::listen(8080);
let conn: Int64 = WsServer::accept(srv);
while true
{
let f: WsFrame = Ws::readMessage(conn);
if f.opcode != 1
{
break;
}
Ws::sendText(conn, Ws::text(f));
}
Ws::close(conn);
return 0;
}
}
Client
import tinox.core.websocket;
class Main
{
fnc main() -> Int32
{
let conn: Int64 = WsClient::connect("localhost", 8080, "/");
WsClient::sendText(conn, "hello from client");
let f: WsFrame = WsClient::readMessage(conn);
println(WsClient::text(f));
WsClient::close(conn);
return 0;
}
}
fn wsSetCompressed(conn: Int64, enabled: Bool) → Nothing
fn wsIsCompressed(conn: Int64) → Bool
fn tinoxDeflateRaw(bytes: List<Int64>) → List<Int64>
fn tinoxInflateRaw(bytes: List<Int64>) → List<Int64>
fn wsLastInflateOk() → Bool
fn tinoxBytesToString(bytes: List<Int64>) → String
class Ws
Methods
fn handshake(conn: Int64) → Bool
fn readFrameGeneric(conn: Int64, requireMasked: Bool) → WsFrame
fn readFrame(conn: Int64) → WsFrame
fn writeFrameGeneric(conn: Int64, opcode: Int64, payload: List<Int64>, masked: Bool) → Nothing
fn writeFrame(conn: Int64, opcode: Int64, payload: List<Int64>) → Nothing
fn readMessageGeneric(conn: Int64, requireMasked: Bool, maskOutgoing: Bool) → WsFrame
fn finishMessage(conn: Int64, maskOutgoing: Bool, opcode: Int64, payload: List<Int64>, compressed: Bool) → WsFrame
fn readMessage(conn: Int64) → WsFrame
fn text(f: WsFrame) → String
fn textToBytes(s: String) → List<Int64>
fn sendText(conn: Int64, s: String) → Nothing
fn sendBinary(conn: Int64, bytes: List<Int64>) → Nothing
fn sendPing(conn: Int64) → Nothing
fn sendCloseGeneric(conn: Int64, code: Int64, masked: Bool) → Nothing
fn sendClose(conn: Int64, code: Int64) → Nothing
fn close(conn: Int64) → Nothing
class WsClient
Methods
fn connect(host: String, port: Int64, path: String) → Int64
fn readMessage(conn: Int64) → WsFrame
fn readFrame(conn: Int64) → WsFrame
fn text(f: WsFrame) → String
fn sendText(conn: Int64, s: String) → Nothing
fn sendBinary(conn: Int64, bytes: List<Int64>) → Nothing
fn sendPing(conn: Int64) → Nothing
fn sendClose(conn: Int64, code: Int64) → Nothing
fn close(conn: Int64) → Nothing
class WsFrame
Fields
fin | Bool | |
opcode | Int64 | |
payload | List<Int64> | |
rsv1 | Bool |
class WsServer
Methods
fn listen(port: Int64) → Int64
fn accept(srv: Int64) → Int64
fn listenTls(port: Int64, certPath: String, keyPath: String) → Int64
fn acceptTls(srv: Int64) → Int64