websocket

Generated by tinox doc

tinox.core.websocket, split out of the bundled stdlib as a standalone tinox-central package.

Echo server

import tinox.core.websocket

class Main
{
    fnc main() -> Int32
    {
        const srv: Int64 = WsServer::listen(8080)
        const conn: Int64 = WsServer::accept(srv)

        while (true)
        {
            const 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
    {
        const conn: Int64 = WsClient::connect("localhost", 8080, "/")
        WsClient::sendText(conn, "hello from client")

        const 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 wsContextTakeoverConfigured() → Bool

fn wsSetContext(conn: Int64, serverNoCtx: Bool, clientNoCtx: Bool, bits: Int64) → Nothing

fn wsHasContext(conn: Int64) → Bool

fn wsDefLock(conn: Int64) → Nothing

fn wsDefUnlock(conn: Int64) → Nothing

fn wsDeflateMsg(conn: Int64, bytes: List<Int64>) → List<Int64>

fn wsInflateMsg(conn: Int64, bytes: List<Int64>) → List<Int64>

fn tinoxBytesToString(bytes: List<Int64>) → String

class Ws

Methods

fn handshake(conn: Int64) → Bool
fn readUpgrade(conn: Int64) → String
fn requestHeader(req: String, name: String) → String
fn rejectUpgrade(conn: Int64, status: Int64, reason: String) → Bool
fn acceptUpgrade(conn: Int64, req: String) → 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

finBool
opcodeInt64
payloadList<Int64>
rsv1Bool

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