Standard library · Network

net.socketio

A Socket.IO client: events, acknowledgements, namespaces and automatic reconnection.

import net.socketio

Socket.IO is the usual live messaging library in the Node.js world. This package is a client for Socket.IO 3 and 4 servers (Engine.IO protocol 4), over WebSocket or HTTP long polling; it has no server of its own. Use it when the other side already speaks Socket.IO, for example a Node.js chat or dashboard backend. When you control both ends and the client is a browser, a plain net.websocket server is simpler, because Socket.IO adds its own packet format on top of the WebSocket.

The model: Dial connects, On sets a listener for an event and the Emit... functions send events. Nothing is read in the background: listeners run only while the program processes messages with Run, RunFor, Pump, Next or EmitAck. The arguments of every event are a JSON array, read with ArgStr, ArgInt and the like. If the sender wants an answer, the event's ack_id is not negative and you answer it with Reply. For several namespaces on one connection, create a Manager.

Things that catch people out:

•

A program that never pumps never hears anything. Pings from the server are answered while you pump, so a client that sleeps for longer than the server's ping timeout is disconnected.

•

Next returns connection events too, such as EV_CONNECT; loop until the kind you stop on, not until the first event that is not EV_EVENT. Its queue starts with the first Next call and keeps the newest event_queue events (256 by default), dropping the oldest.

•

Free what you build. ArgsFree for argument lists and AckFree for answers, or a long running client keeps growing.

•

Socket.IO 2 servers (from before 2020) speak an older protocol and are not supported.

Handling events in your own loop

Listeners with On are the usual style, but sometimes a plain loop reads better: a worker that handles one event at a time, or a program that must also do other work between messages. Next waits up to the given milliseconds and returns one Event. Its kind says what it is: a message from the server (EV_EVENT, with the name and the arguments), a change of the connection such as EV_DISCONNECT (the reason is in message), or EV_TIMEOUT when nothing came.

net-socketio-next-loop.salam
import net.socketio
import net.websocket

mut server := websocket.Server {}

func fake_server():
    mut conn := websocket.Accept(server)
    _ := websocket.SendText(
        conn, `0{"sid":"s1","upgrades":[],"pingInterval":20000,"pingTimeout":5000}`
    )
    m := websocket.Poll(conn, 3000)
    if m.kind == websocket.TEXT and m.text == "40":
        _ := websocket.SendText(conn, `40{"sid":"a1"}`)
        _ := websocket.SendText(conn, `42["price","BTC",61250]`)
        _ := websocket.SendText(conn, `42["price","ETH",2410]`)
        _ := websocket.SendText(conn, `42["halt","maintenance"]`)
        _ := websocket.SendText(conn, "41")
    end
    _ := websocket.Poll(conn, 1000)
    websocket.Close(conn)
end

func main:
    server = websocket.Listen(0)
    t := spawn(fake_server)
    mut o := socketio.NewOptions()
    o.transports = socketio.TRANSPORT_WEBSOCKET
    o.reconnection = false
    c := socketio.DialWith("http://127.0.0.1:" + websocket.Port(server), o)

    mut going := true
    until going:
        e := socketio.Next(c, 3000)
        if e.kind == socketio.EV_EVENT and e.name == "price":
            println "price", socketio.ArgStr(e, 0), socketio.ArgInt(e, 1)
        else e.kind == socketio.EV_EVENT:
            println "event", e.name, socketio.ArgStr(e, 0)
        else e.kind == socketio.EV_DISCONNECT:
            println "disconnected:", e.message, e.message == socketio.REASON_SERVER_DISCONNECT
            going = false
        else e.kind == socketio.EV_TIMEOUT:
            println "nothing arrived in time"
            going = false
        end
    end
    socketio.Close(c)
    join(t)
    websocket.CloseServer(server)
end
Output
price BTC 61250
price ETH 2410
event halt maintenance
disconnected: io server disconnect true

The program brings its own tiny server, which speaks the Socket.IO wire format over a WebSocket, so it runs without Node.js. A real server sends the same packets: 42["price","BTC",61250] is an event named price with two arguments, and 41 is the server closing the namespace, which arrives as REASON_SERVER_DISCONNECT. After that reason the client does not reconnect by itself, because the server meant it.

Logging in with a token

Socket.IO servers usually check the user in a middleware that reads the auth object of the connection. Put that JSON in Options.auth before dialling. When the middleware says no, the server answers with a connect error instead of a session; Refused is then true and RefusalReason holds the message the server gave.

net-socketio-auth.salam
import net.socketio

func main:
    mut o := socketio.NewOptions()
    o.auth = `{"token":"eyJhbGciOiJIUzI1NiJ9.e30.x"}`
    o.reconnection = false
    c := socketio.DialWith("https://chat.example.com", o)
    if socketio.Refused(c):
        println "the server refused us:", socketio.RefusalReason(c)
        ret 1
    end
    if not socketio.IsConnected(c):
        println "could not connect:", socketio.LastError(c)
        ret 1
    end
    println "connected as", socketio.Id(c), "over", socketio.TransportName(c)
    socketio.Close(c)
    ret 0
end

This needs a running server, so it is only checked here. With a Node.js server, the matching check is an io.use((socket, next) => ...) that reads socket.handshake.auth.token and calls next(new Error("...")) to refuse.

Acknowledgements in both directions

An acknowledgement is Socket.IO's request and reply: the sender numbers an event and the other side answers that number. EmitAck sends an event and waits, up to the time you give, for the server's answer; ok is false when it did not come in time. The other way round, when the server sends an event with an id, e.ack_id holds it and Reply, ReplyStr or ReplyJSON answers it. The fake server below shows both packets on the wire: 420[...] is the client's event with ack id 0 and 4317["yes"] is the client's answer to the server's ack id 17.

net-socketio-ack.salam
import net.socketio
import net.websocket
import encoding.json

mut server := websocket.Server {}
mut seen := Vector {} as Vector<str>

func fake_server():
    mut conn := websocket.Accept(server)
    _ := websocket.SendText(
        conn, `0{"sid":"s1","upgrades":[],"pingInterval":20000,"pingTimeout":5000}`
    )
    if websocket.ReceiveText(conn) != "40": ret end
    _ := websocket.SendText(conn, `40{"sid":"a1"}`)
    join := websocket.ReceiveText(conn)
    seen.Push(join)
    _ := websocket.SendText(conn, `430[{"ok":true,"members":3}]`)
    _ := websocket.SendText(conn, `4217["confirm","order 1042"]`)
    seen.Push(websocket.ReceiveText(conn))
    _ := websocket.SendText(conn, "41")
    _ := websocket.Poll(conn, 1000)
    websocket.Close(conn)
end

func main:
    server = websocket.Listen(0)
    t := spawn(fake_server)
    mut o := socketio.NewOptions()
    o.transports = socketio.TRANSPORT_WEBSOCKET
    o.reconnection = false
    c := socketio.DialWith("http://127.0.0.1:" + websocket.Port(server), o)

    mut a := socketio.NewArgs()
    socketio.AddStr(a, "room-1")
    mut answer := socketio.EmitAck(c, "join", a, 2000)
    socketio.ArgsFree(a)
    println "join answered:",
        answer.ok,
        "members:",
        json.GetInt(socketio.AckArg(answer, 0), "members")
    socketio.AckFree(answer)

    mut going := true
    until going:
        e := socketio.Next(c, 3000)
        if e.kind == socketio.EV_EVENT and e.name == "confirm":
            println "server asks:", socketio.ArgStr(e, 0), "ack id", e.ack_id
            _ := socketio.ReplyStr(e, "yes")
        else e.kind == socketio.EV_DISCONNECT or e.kind == socketio.EV_TIMEOUT:
            going = false
        end
    end
    socketio.Close(c)
    join(t)
    websocket.CloseServer(server)
    println "the server saw:"
    each line in seen: println " ", line end
end
Output
join answered: true members: 3
server asks: order 1042 ack id 17
the server saw:
  420["join","room-1"]
  4317["yes"]

Answer each acknowledged event once. Servers usually put a timeout on their own emitWithAck, so reply before you start slow work, or reply with a "started" status and send the result as a separate event.

A bot that stays connected

A long running client joins a room, answers some messages and survives network trouble. EmitAck sends an event and waits for the server's answer, which is how you know the join worked. Run then handles events until the client is closed, and reconnects on its own after a dropped connection, waiting reconnection_delay milliseconds and longer each time up to reconnection_delay_max. The disconnect and reconnect listeners let you log both.

net-socketio-chat-bot.salam
import net.socketio
import str

mut client := socketio.Client {}

func main:
    mut o := socketio.NewOptions()
    o.reconnection_attempts = 10
    o.reconnection_delay = 2000
    client = socketio.DialWith("http://localhost:3000", o)
    if not socketio.IsConnected(client):
        println "cannot reach the chat:", socketio.LastError(client)
        ret 1
    end

    mut a := socketio.NewArgs()
    socketio.AddStr(a, "support")
    mut k := socketio.EmitAck(client, "join", a, 5000)
    socketio.ArgsFree(a)
    if not k.ok:
        println "joining the room timed out"
        ret 1
    end
    println "joined support, members:", socketio.AckInt(k, 0)
    socketio.AckFree(k)

    socketio.On(client, "message", (e: socketio.Event): text := socketio.ArgStr(e, 1) if str.StartsWith(text, "!time"): _ := socketio.EmitStr(client, "message", "office hours are 9 to 17") end end)
    socketio.On(client, "disconnect", (e: socketio.Event): println "lost the connection:", e.message end)
    socketio.On(client, "reconnect", (e: socketio.Event): _ := e println "back after", socketio.Attempts(client), "attempts" end)
    socketio.Run(client)
    ret 0
end

A bot that only reacts to events can stay in Run for its whole life; it returns when Close is called or when reconnection gives up.

Which way to receive

SituationUse
The program only reacts to eventsOn listeners and Run
A test or a script that runs for a while and stopsRunFor
Your own main loop, with other work between eventsPump with a short timeout, once per turn of the loop
One event at a time, in order, without callbacksNext
Several namespaces on one connectionNewManager, Of, then PumpManager

Types

Bytes

#
struct Bytes

The bytes of one binary part.

NameTypeDescription
ptrvoid*The pointer.
lenint = 0The length.
net-socketio-Bytes.salam
import net.socketio

func main:
    mut b := socketio.BytesFromStr("Salam")
    println b.len, socketio.BytesAt(b, 0)
    println socketio.BytesToStr(b)
    println socketio.BytesToBase64(b)
    socketio.BytesFree(b)
    mut c := socketio.NewBytes("hello" as void*, 4)
    println socketio.BytesToStr(c)
    socketio.BytesFree(c)

    mut a := socketio.NewArgs()
    socketio.AddStr(a, "file.txt")
    socketio.AddBinaryStr(a, "abc")
    println socketio.ArgsJSON(a, "upload")
    println a.bins.Len()
    socketio.ArgsFree(a)
end
Output
5 83
Salam
U2FsYW0=
hell
["upload","file.txt",{"_placeholder":true,"num":0}]
1

Packet

#
struct Packet

One Socket.IO packet.

NameTypeDescription
kindint = -1The kind.
nspstr = "/"The namespace.
idint = -1The acknowledgement number; -1 means no acknowledgement.
datastr = ""The data as JSON.
attachmentsint = 0The number of binary parts.
okbool = falseThe packet was read correctly.
net-socketio-Packet.salam
import net.socketio

func main:
    mut p := socketio.Packet {}
    p.kind = socketio.PKT_EVENT
    p.nsp = "/chat"
    p.id = 7
    p.data = `["hi",1]`
    text := socketio.EncodePacket(p)
    println text
    d := socketio.DecodePacket(text)
    println d.ok, d.kind, d.nsp, d.id, d.data
    bad := socketio.DecodePacket("x")
    println bad.ok

    payload := socketio.EncodeEngine(socketio.EIO_MESSAGE, text)
    println payload
    println socketio.EngineKind(payload) == socketio.EIO_MESSAGE
    println socketio.EngineBody(payload)

    mut items := Vector {} as Vector<str>
    items.Push("2")
    items.Push(payload)
    body := socketio.JoinPayloads(items)
    parts := socketio.SplitPayloads(body)
    println parts.Len(), parts.Get(0), parts.Get(1)

    arr := socketio.SplitJSONArray(`["a", {"b":[1,2]}, 3]`)
    println arr.Len(), arr.Get(1)

    ph := socketio.Placeholder(0)
    println ph
    println socketio.PlaceholderNum(ph), socketio.PlaceholderNum("12")
end
Output
2/chat,7["hi",1]
true 2 /chat 7 ["hi",1]
false
42/chat,7["hi",1]
true
2/chat,7["hi",1]
2 2 42/chat,7["hi",1]
3 {"b":[1,2]}
{"_placeholder":true,"num":0}
0 -1

Endpoint

#
struct Endpoint

A parsed server URL.

NameTypeDescription
securebool = falseHTTPS or WSS.
hoststr = "localhost"The host.
portint = 80The port; 80 or 443 if it is not given.
pathstr = "/socket.io"The Socket.IO path.
namespacestr = "/"The namespace, from the URL path.
querystr = ""The query.
okbool = falseThe URL is valid.
net-socketio-URL.salam
import net.socketio

func show(url: str):
    e := socketio.ParseURL(url)
    if not e.ok:
        println url, "invalid"
        ret
    end
    println e.host, e.port, e.secure, e.namespace, "query=" + e.query
    println socketio.Origin(e)
end

func main:
    show("http://localhost:3000")
    show("https://example.com/admin/?token=abc")
    show("ws://[::1]:8080/chat")
    show("ftp://example.com")
end
Output
localhost 3000 false / query=
http://localhost:3000
example.com 443 true /admin query=token=abc
https://example.com
::1 8080 false /chat query=
http://[::1]:8080
ftp://example.com invalid

Args

#
struct Args

The arguments of one message.

NameTypeDescription
itemsVector<str>The arguments as JSON.
binsVector<Bytes>The binary parts.
net-socketio-Args.salam
import net.socketio
import encoding.value

func main:
    mut a := socketio.NewArgs()
    socketio.AddStr(a, "hello \"world\"")
    socketio.AddInt(a, 42)
    socketio.AddFloat(a, 2.5)
    socketio.AddBool(a, true)
    socketio.AddNull(a)
    socketio.AddJSON(a, `{"x":1}`)
    println socketio.ArgsCount(a)
    text := socketio.ArgsJSON(a, "message")
    println text
    println socketio.ItemCount(text)
    println socketio.ItemStr(text, 1)
    println socketio.ItemInt(text, 2)
    println socketio.ItemFloat(text, 3)
    println socketio.ItemBool(text, 4)
    println socketio.Item(text, 6)
    println socketio.Item(text, 9).Len()
    socketio.ArgsFree(a)

    mut v := socketio.ItemValue(text, 2)
    println value.IsNumber(v), value.AsInt(v)
    mut a2 := socketio.NewArgs()
    socketio.AddValue(a2, v)
    socketio.AddBytes(a2, "xyz" as void*, 3)
    println socketio.ArgsJSON(a2, "")
    socketio.ArgsFree(a2)
    value.ValueFree(v)
end
Output
6
["message","hello \"world\"",42,2.5,true,null,{"x":1}]
7
hello "world"
42
2.5
true
{"x":1}
0
true 42
[42,{"_placeholder":true,"num":0}]

Options

#
struct Options

Connection options.

NameTypeDescription
pathstr = "/socket.io"The path of the Socket.IO server.
querystr = ""An extra query for the URL.
authstr = ""Authentication data as JSON, sent when connecting to the namespace.
headersstr = ""Extra HTTP headers, one per line.
transportsintThe transport, one of the TRANSPORT_... constants.
reconnectionbool = trueReconnect automatically after a disconnect.
reconnection_attemptsint = 0The most attempts; zero means no limit.
reconnection_delayint = 1000The delay before the first attempt in milliseconds; it doubles every time.
reconnection_delay_maxint = 5000The longest delay.
randomization_factorint = 50A random percentage added to or taken from the delay so that all clients do not come back at the same moment.
timeoutint = 20000The connect timeout in milliseconds.
insecurebool = falseDo not check the TLS certificate; for testing only.
auto_connectbool = trueThe client connects right away.
event_queueint = 256The most events Next keeps waiting; when it is full the oldest is dropped.
ack_timeoutint = 0The acknowledgement timeout in milliseconds used when EmitAck is given 0.
retriesint = 0How many times to resend messages that got no acknowledgement.
trailing_slashbool = trueAdd a slash to the end of the path, like the JavaScript client.
remember_upgradebool = falseIf the upgrade to WebSocket worked once, use WebSocket directly next time.
net-socketio-Options.salam
import net.socketio

func main:
    mut o := socketio.NewOptions()
    println o.path, o.reconnection, o.reconnection_delay, o.timeout
    println o.transports == socketio.TRANSPORT_AUTO
    o.transports = socketio.TRANSPORT_WEBSOCKET
    o.auth = `{"token":"abc"}`
    o.auto_connect = false
    println o.transports, o.auth, o.auto_connect
    println socketio.TRANSPORT_POLLING,
        socketio.REASON_SERVER_DISCONNECT,
        socketio.REASON_PING_TIMEOUT
    println socketio.PUMP_OK, socketio.PUMP_TIMEOUT, socketio.PUMP_CLOSED
end
Output
/socket.io true 1000 20000
true
1 {"token":"abc"} false
2 io server disconnect ping timeout
0 1 2

Client

#
struct Client

One socket on one namespace.

NameTypeDescription
pvoid*The internal pointer.
net-socketio-Client.salam
import net.socketio
import net.websocket
import str

mut server := websocket.Server {}
mut report := ""

func test_server():
    mut conn := websocket.Accept(server)
    _ := websocket.SendText(
        conn, `0{"sid":"s1","upgrades":[],"pingInterval":20000,"pingTimeout":5000}`
    )
    mut going := true
    until going:
        m := websocket.Poll(conn, 3000)
        if m.kind != websocket.TEXT:
            break
        end
        packet := m.text.Substr(1, m.text.Len() - 1)
        if packet == "0":
            _ := websocket.SendText(conn, `40{"sid":"a1"}`)
        else str.StartsWith(packet, `2["chat"`):
            _ := websocket.SendText(conn, `42["chat","welcome"]`)
            _ := websocket.SendText(conn, `429["question","2+2"]`)
        else str.Contains(packet, `"add"`):
            id := packet.Substr(1, str.Find(packet, "[") - 1)
            _ := websocket.SendText(conn, "43" + id + "[5]")
        else str.StartsWith(packet, "39"):
            report += "reply: " + packet.Substr(2, packet.Len() - 2)
        else packet == "1":
            going = false
        end
    end
    websocket.Close(conn)
end

func main:
    server = websocket.Listen(0)
    t := spawn(test_server)
    mut o := socketio.NewOptions()
    o.transports = socketio.TRANSPORT_WEBSOCKET
    o.reconnection = false
    c := socketio.DialWith("http://127.0.0.1:" + websocket.Port(server), o)
    println socketio.IsConnected(c),
        socketio.Sid(c),
        socketio.Id(c),
        socketio.Namespace(c),
        socketio.TransportName(c)

    socketio.On(c, "chat", (e: socketio.Event): println "message:", socketio.ArgStr(e, 0) end)
    socketio.On(c, "question", (e: socketio.Event): println "question:", socketio.ArgStr(e, 0), e.ack_id >= 0 _ := socketio.ReplyStr(e, "four") end)
    println socketio.ListenerCount(c, "chat"), socketio.HasListeners(c, "news")
    _ := socketio.EmitStr(c, "chat", "hello")
    socketio.RunFor(c, 500)

    mut a := socketio.NewArgs()
    socketio.AddInt(a, 2)
    socketio.AddInt(a, 3)
    mut k := socketio.EmitAck(c, "add", a, 2000)
    println k.ok, socketio.AckInt(k, 0)
    socketio.AckFree(k)
    socketio.ArgsFree(a)

    socketio.Close(c)
    join(t)
    websocket.CloseServer(server)
    println report
end
Output
true s1 a1 / websocket
1 false
message: welcome
question: 2+2 true
true 5
reply: ["four"]

Manager

#
struct Manager

A connection that several namespaces work on.

NameTypeDescription
pvoid*The internal pointer.
net-socketio-Manager.salam
import net.socketio

func main:
    mut o := socketio.NewOptions()
    o.auth = `{"token":"abc"}`
    o.auto_connect = false
    m := socketio.NewManager("https://example.com", o)
    socketio.SetReconnection(m, true)
    socketio.SetReconnectionAttempts(m, 5)
    socketio.SetReconnectionDelay(m, 500)
    socketio.SetReconnectionDelayMax(m, 10000)
    socketio.SetRandomizationFactor(m, 20)
    socketio.SetTimeout(m, 5000)
    println socketio.OptionsOf(m).reconnection_attempts

    public := socketio.Of(m, "/")
    admin := socketio.Of(m, "/admin")
    socketio.SetAuth(admin, `{"role":"admin"}`)
    println socketio.AuthOf(admin), socketio.Sockets(m).Len()
    if not socketio.Open(m):
        println "error:", socketio.ManagerError(m)
        ret
    end
    println socketio.IsOpen(m)
    _ := socketio.Connect(public)
    _ := socketio.Connect(admin)
    if socketio.Refused(admin):
        println "refused:", socketio.RefusalReason(admin)
    end
    println socketio.Active(public), socketio.Disconnected(public), socketio.Recovered(public)
    println socketio.Transport(public),
        socketio.PingInterval(public),
        socketio.PingTimeout(public),
        socketio.MaxPayload(public)
    println socketio.Buffered(public),
        socketio.Pending(public),
        socketio.Queued(public),
        socketio.Attempts(public)
    println socketio.EndpointOf(public).host, socketio.ManagerOf(public).p == m.p
    _ := socketio.PumpManager(m, 1000)
    socketio.Disconnect(admin)
    socketio.CloseManager(m)
end

Event

#
struct Event

An event that arrived.

NameTypeDescription
kindintThe kind of event.
namestr = ""The event name.
nspstr = "/"The namespace.
datastr = "[]"The arguments as a JSON array.
ack_idint = -1The acknowledgement number if the sender wants one; otherwise -1.
messagestr = ""A description, for error and disconnect events.
binsVector<Bytes>The binary parts.
clientClientThe socket that received the event.

The example for this item is shown with the ones above: net-socketio-Client.salam

Ack

#
struct Ack

An acknowledgement reply.

NameTypeDescription
okbool = falseThe reply arrived before the timeout.
idint = -1The acknowledgement number.
datastr = "[]"The arguments as a JSON array.
binsVector<Bytes>The binary parts.

The example for this item is shown with the ones above: net-socketio-Client.salam

Constants and variables

Engine packet kinds

EIO_…#

Socket.IO runs on a layer called Engine.IO. Every message on that layer starts with a digit that gives its kind: open, close, ping, pong, message, upgrade and noop. Socket.IO packets travel inside messages of the "message" kind.

NameValue
EIO_OPEN
0
EIO_CLOSE
1
EIO_PING
2
EIO_PONG
3
EIO_MESSAGE
4
EIO_UPGRADE
5
EIO_NOOP
6

The example for this item is shown with the ones above: net-socketio-Packet.salam

Socket.IO packet kinds

PKT_…#

The kinds of Socket.IO packet: connecting to a namespace, disconnecting, an event, an acknowledgement, a connect error, and the binary event and binary acknowledgement whose bytes follow the packet separately.

NameValue
PKT_CONNECT
0
PKT_DISCONNECT
1
PKT_EVENT
2
PKT_ACK
3
PKT_CONNECT_ERROR
4
PKT_BINARY_EVENT
5
PKT_BINARY_ACK
6

The example for this item is shown with the ones above: net-socketio-Packet.salam

TRANSPORT_AUTO

#
const TRANSPORT_AUTO: i32 = 0

Transport: HTTP polling first, then an upgrade to WebSocket if the server allows it.

The example for this item is shown with the ones above: net-socketio-Options.salam

TRANSPORT_WEBSOCKET

#
const TRANSPORT_WEBSOCKET: i32 = 1

Transport: WebSocket only.

The example for this item is shown with the ones above: net-socketio-Client.salam

TRANSPORT_POLLING

#
const TRANSPORT_POLLING: i32 = 2

Transport: HTTP polling only.

The example for this item is shown with the ones above: net-socketio-Options.salam

Event kinds

EV_…#

The value of the kind field in the event that Next returns. A message event is one of the server's messages; the rest report on the connection itself: connecting and disconnecting, errors, reconnection attempts, pings, timeouts and the upgrade to WebSocket. Listeners are called with the English names of these events, such as connect and disconnect.

NameValue
EV_NONE
0
EV_EVENT
1
EV_CONNECT
2
EV_DISCONNECT
3
EV_CONNECT_ERROR
4
EV_ERROR
5
EV_RECONNECT
6
EV_RECONNECT_ATTEMPT
7
EV_RECONNECT_ERROR
8
EV_RECONNECT_FAILED
9
EV_PING
10
EV_TIMEOUT
11
EV_UPGRADE
12
net-socketio-Ack.salam
import net.socketio
import encoding.value

func main:
    c := socketio.Dial("http://localhost:3000")
    if not socketio.IsConnected(c):
        println socketio.LastError(c)
        ret
    end
    socketio.OnAny(c, (e: socketio.Event): println "received:", e.name, socketio.ArgCount(e) end)
    socketio.Once(c, "welcome", (e: socketio.Event): println socketio.Arg(e, 0) end)
    socketio.OnAnyOutgoing(c, (e: socketio.Event): println "sent:", e.name end)

    socketio.PrependAny(c, (e: socketio.Event): println "first of all:", e.name end)
    socketio.PrependAnyOutgoing(c, (e: socketio.Event): println "sending:", e.name end)
    println socketio.AnyListenerCount(c)

    _ := socketio.Emit(c, "ping")
    _ := socketio.EmitInt(c, "score", 12)
    _ := socketio.EmitFloat(c, "temp", 21.5)
    _ := socketio.EmitBool(c, "ready", true)
    _ := socketio.EmitJSON(c, "user", `{"name":"Ali"}`)
    _ := socketio.EmitBytes(c, "file", "abc" as void*, 3)
    _ := socketio.Send(c, "a plain message")

    mut a := socketio.NewArgs()
    socketio.AddStr(a, "room-1")
    _ := socketio.EmitArgs(c, "join", a)
    _ := socketio.EmitVolatile(c, "cursor", a)
    _ := socketio.EmitWithAck(c, "join", a, 2000, (k: socketio.Ack): println k.ok, socketio.AckCount(k), socketio.AckStr(k, 0) println socketio.AckArg(k, 1), socketio.AckFloat(k, 1), socketio.AckBool(k, 2) if socketio.AckIsBinary(k, 3): println socketio.AckBytes(k, 3).len end mut v := socketio.AckValue(k, 0) value.ValueFree(v) end)
    socketio.ArgsFree(a)

    mut e := socketio.Next(c, 5000)
    if e.kind == socketio.EV_EVENT:
        println socketio.ArgInt(e, 0), socketio.ArgFloat(e, 1), socketio.ArgBool(e, 2)
        if socketio.ArgIsBinary(e, 3):
            b := socketio.ArgBytes(e, 3)
            println b.len
        end
        if e.ack_id >= 0:
            if socketio.ArgCount(e) > 1:
                mut r := socketio.NewArgs()
                socketio.AddBool(r, true)
                _ := socketio.Reply(e, r)
                socketio.ArgsFree(r)
            else:
                _ := socketio.ReplyJSON(e, `{"ok":true}`)
            end
        end
    else e.kind == socketio.EV_DISCONNECT:
        println "disconnected:", e.message
    end
    socketio.EventFree(e)

    mut e2 := socketio.NextEvent(c, 5000)
    mut v2 := socketio.ArgValue(e2, 0)
    println value.IsNumber(v2)
    value.ValueFree(v2)
    socketio.EventFree(e2)

    _ := socketio.Pump(c, 100)
    socketio.Off(c, "welcome")
    socketio.OffAny(c)
    socketio.OffAnyOutgoing(c)
    socketio.OffAll(c)
    socketio.Run(c)
end

Disconnect reasons

REASON_…#

The text in the message field of a disconnect event, telling why the connection ended: the server or the program itself closed it, a ping did not arrive in time, the transport closed or failed, or a packet could not be read.

NameValue
REASON_SERVER_DISCONNECT
"io server disconnect"
REASON_CLIENT_DISCONNECT
"io client disconnect"
REASON_PING_TIMEOUT
"ping timeout"
REASON_TRANSPORT_CLOSE
"transport close"
REASON_TRANSPORT_ERROR
"transport error"
REASON_PARSE_ERROR
"parse error"

The example for this item is shown with the ones above: net-socketio-Options.salam

Pump results

PUMP_…#

The result of Pump and PumpManager: something arrived and was handled, the timeout ran out, or the connection is closed.

NameValue
PUMP_OK
0
PUMP_TIMEOUT
1
PUMP_CLOSED
2

The example for this item is shown with the ones above: net-socketio-Options.salam

Functions

EncodePacket

#
func EncodePacket(p: Packet): str

Turns a packet into protocol text.

The example for this item is shown with the ones above: net-socketio-Packet.salam

DecodePacket

#
func DecodePacket(text: str): Packet

Turns text back into a packet; if it is invalid, ok is false.

The example for this item is shown with the ones above: net-socketio-Packet.salam

EncodeEngine

#
func EncodeEngine(kind: int, body: str): str

An Engine.IO message with a kind and a body.

The example for this item is shown with the ones above: net-socketio-Packet.salam

EngineKind

#
func EngineKind(payload: str): int

The kind of an Engine.IO message.

The example for this item is shown with the ones above: net-socketio-Packet.salam

EngineBody

#
func EngineBody(payload: str): str

The body of an Engine.IO message, without the kind digit.

The example for this item is shown with the ones above: net-socketio-Packet.salam

SplitPayloads

#
func SplitPayloads(body: str): Vector<str>

Splits a polling response into messages; the separator is character 30.

The example for this item is shown with the ones above: net-socketio-Packet.salam

JoinPayloads

#
func JoinPayloads(items: Vector<str>): str

Joins messages together for one polling request.

The example for this item is shown with the ones above: net-socketio-Packet.salam

SplitJSONArray

#
func SplitJSONArray(text: str): Vector<str>

Splits a JSON array into the text of its top level elements.

The example for this item is shown with the ones above: net-socketio-Packet.salam

Placeholder

#
func Placeholder(num: int): str

The placeholder for the binary part with this number.

The example for this item is shown with the ones above: net-socketio-Packet.salam

PlaceholderNum

#
func PlaceholderNum(frag: str): int

The number of a placeholder; -1 if it is not a placeholder.

The example for this item is shown with the ones above: net-socketio-Packet.salam

NewBytes

#
func NewBytes(ptr: void*, n: int): Bytes

Copies bytes.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

BytesFromStr

#
func BytesFromStr(s: str): Bytes

The bytes of a string.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

BytesToStr

#
func BytesToStr(b: Bytes): str

The bytes as a string.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

BytesToBase64

#
func BytesToBase64(b: Bytes): str

The bytes as base64.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

BytesAt

#
func BytesAt(b: Bytes, i: int): int

One byte, from 0 to 255.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

BytesFree

#
func BytesFree(b &: Bytes)

Frees the memory.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

ParseURL

#
func ParseURL(raw: str): Endpoint

Parses a URL; the http, https, ws and wss schemes are accepted.

The example for this item is shown with the ones above: net-socketio-URL.salam

Origin

#
func Origin(e: Endpoint): str

The origin of the URL, such as https://example.com; the default port is left out.

The example for this item is shown with the ones above: net-socketio-URL.salam

NewArgs

#
func NewArgs(): Args

An empty argument list.

The example for this item is shown with the ones above: net-socketio-Client.salam

AddStr

#
func AddStr(a &: Args, s: str)

Adds a string.

The example for this item is shown with the ones above: net-socketio-Args.salam

AddFloat

#
func AddFloat(a &: Args, n: f64)

A float.

The example for this item is shown with the ones above: net-socketio-Args.salam

AddBool

#
func AddBool(a &: Args, b: bool)

A boolean.

The example for this item is shown with the ones above: net-socketio-Args.salam

AddJSON

#
func AddJSON(a &: Args, raw: str)

Ready JSON text; an empty string becomes null.

The example for this item is shown with the ones above: net-socketio-Args.salam

AddValue

#
func AddValue(a &: Args, v: value.Value)

An encoding value.

The example for this item is shown with the ones above: net-socketio-Args.salam

AddBytes

#
func AddBytes(a &: Args, ptr: void*, n: int)

Sends the bytes separately and puts a placeholder in their place.

The example for this item is shown with the ones above: net-socketio-Args.salam

AddBinaryStr

#
func AddBinaryStr(a &: Args, s: str)

Sends the bytes of a string as binary.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

ArgsCount

#
func ArgsCount(a: Args): int

The number of arguments.

The example for this item is shown with the ones above: net-socketio-Args.salam

ArgsFree

#
func ArgsFree(a &: Args)

Frees the memory.

The example for this item is shown with the ones above: net-socketio-Client.salam

ArgsJSON

#
func ArgsJSON(a: Args, name: str): str

The JSON array that is sent; the event name, if not empty, comes first.

The example for this item is shown with the ones above: net-socketio-Args.salam

ItemCount

#
func ItemCount(raw: str): int

The number of elements in a JSON array.

The example for this item is shown with the ones above: net-socketio-Args.salam

Item

#
func Item(raw: str, i: int): str

The JSON text of one element; an empty string if there is none.

The example for this item is shown with the ones above: net-socketio-Args.salam

ItemStr

#
func ItemStr(raw: str, i: int): str

The element as a string.

The example for this item is shown with the ones above: net-socketio-Args.salam

ItemInt

#
func ItemInt(raw: str, i: int): i64

The element as an integer; a numeric string is read too.

The example for this item is shown with the ones above: net-socketio-Args.salam

ItemFloat

#
func ItemFloat(raw: str, i: int): f64

The element as a float.

The example for this item is shown with the ones above: net-socketio-Args.salam

ItemBool

#
func ItemBool(raw: str, i: int): bool

The element as a boolean; a nonzero number and the string true count as true.

The example for this item is shown with the ones above: net-socketio-Args.salam

ItemValue

#
func ItemValue(raw: str, i: int): value.Value

The element as an encoding value.

The example for this item is shown with the ones above: net-socketio-Args.salam

NewOptions

#
func NewOptions(): Options

The default options.

The example for this item is shown with the ones above: net-socketio-Client.salam

NewManager

#
func NewManager(url: str, opts: Options): Manager

A new manager for a URL.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Of

#
func Of(m: Manager, nsp: str): Client

The socket for a namespace on the manager.

The example for this item is shown with the ones above: net-socketio-Bytes.salam

ManagerOf

#
func ManagerOf(c: Client): Manager

The manager the socket is on.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Dial

#
func Dial(url: str): Client

Connects to a URL; the URL path is the namespace. If it does not connect, see why with LastError.

The example for this item is shown with the ones above: net-socketio-Client.salam

DialWith

#
func DialWith(url: str, opts: Options): Client

Like the function above, with options.

The example for this item is shown with the ones above: net-socketio-Client.salam

Connect

#
func Connect(c: Client): bool

Connects the socket; if it was connected before, connects it again.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Disconnect

#
func Disconnect(c: Client)

Leaves the namespace; no automatic reconnection follows.

The example for this item is shown with the ones above: net-socketio-Manager.salam

CloseManager

#
func CloseManager(m: Manager)

Closes the connection and all its sockets.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Pump

#
func Pump(c: Client, timeout_ms: int): int

Handles the messages that arrive within this timeout and calls the listeners.

The example for this item is shown with the ones above: net-socketio-Options.salam

PumpManager

#
func PumpManager(m: Manager, timeout_ms: int): int

Like the function above, for all the manager's sockets.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Next

#
func Next(c: Client, timeout_ms: int): Event

The next event from the queue, or an event of kind EV_TIMEOUT if nothing arrived within the timeout; a negative timeout waits forever. Listeners are called too. The queue starts with the first call.

The example for this item is shown with the ones above: net-socketio-Ack.salam

NextEvent

#
func NextEvent(c: Client, timeout_ms: int): Event

Like the function above, but only message events.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Run

#
func Run(c: Client)

Handles messages until the socket closes.

The example for this item is shown with the ones above: net-socketio-Client.salam

RunFor

#
func RunFor(c: Client, ms: int)

Handles messages for this many milliseconds.

The example for this item is shown with the ones above: net-socketio-Client.salam

On

#
func On(c: Client, name: str, cb: func(Event))

Sets a listener for an event.

The example for this item is shown with the ones above: net-socketio-Client.salam

Once

#
func Once(c: Client, name: str, cb: func(Event))

A listener that is called only once.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Off

#
func Off(c: Client, name: str)

Removes the listeners of an event.

The example for this item is shown with the ones above: net-socketio-Ack.salam

OffAll

#
func OffAll(c: Client)

Removes all listeners.

The example for this item is shown with the ones above: net-socketio-Ack.salam

OnAny

#
func OnAny(c: Client, cb: func(Event))

A listener for every message event.

The example for this item is shown with the ones above: net-socketio-Ack.salam

OffAny

#
func OffAny(c: Client)

Removes the listeners for every event.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitArgs

#
func EmitArgs(c: Client, name: str, a: Args): bool

Sends an event with arguments. If not connected, the message waits in the queue. Reserved names, such as connect, are refused.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitVolatile

#
func EmitVolatile(c: Client, name: str, a: Args): bool

Like the function above, but if not connected, the message is dropped.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Emit

#
func Emit(c: Client, name: str): bool

An event with no arguments.

The example for this item is shown with the ones above: net-socketio-Client.salam

EmitStr

#
func EmitStr(c: Client, name: str, s: str): bool

An event with one string.

The example for this item is shown with the ones above: net-socketio-Client.salam

EmitInt

#
func EmitInt(c: Client, name: str, n: i64): bool

With one integer.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitFloat

#
func EmitFloat(c: Client, name: str, n: f64): bool

With one float.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitBool

#
func EmitBool(c: Client, name: str, b: bool): bool

With one boolean.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitJSON

#
func EmitJSON(c: Client, name: str, raw: str): bool

With one JSON text.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitBytes

#
func EmitBytes(c: Client, name: str, ptr: void*, n: int): bool

With binary bytes.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EmitAck

#
func EmitAck(c: Client, name: str, a: Args, timeout_ms: int): Ack

Sends an event and waits until the acknowledgement arrives or the timeout runs out; 0 uses ack_timeout, a negative value waits forever. Other events that arrive meanwhile go to the listeners.

The example for this item is shown with the ones above: net-socketio-Client.salam

EmitWithAck

#
func EmitWithAck(c: Client, name: str, a: Args, timeout_ms: int, cb: func(Ack)): bool

Sends an event and calls the given function when the acknowledgement arrives or the timeout runs out; it does not wait.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Reply

#
func Reply(ev: Event, a: Args): bool

Answers an event that asked for an acknowledgement.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ReplyJSON

#
func ReplyJSON(ev: Event, raw: str): bool

Answers with one JSON text.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ReplyStr

#
func ReplyStr(ev: Event, s: str): bool

Answers with one string.

The example for this item is shown with the ones above: net-socketio-Client.salam

ArgCount

#
func ArgCount(ev: Event): int

The number of arguments of the event.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Arg

#
func Arg(ev: Event, i: int): str

The JSON text of one argument.

The example for this item is shown with the ones above: net-socketio-Client.salam

ArgStr

#
func ArgStr(ev: Event, i: int): str

The argument as a string.

The example for this item is shown with the ones above: net-socketio-Client.salam

ArgInt

#
func ArgInt(ev: Event, i: int): i64

An integer argument.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ArgFloat

#
func ArgFloat(ev: Event, i: int): f64

A float argument.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ArgBool

#
func ArgBool(ev: Event, i: int): bool

A boolean argument.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ArgValue

#
func ArgValue(ev: Event, i: int): value.Value

The argument as an encoding value.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ArgIsBinary

#
func ArgIsBinary(ev: Event, i: int): bool

The argument is binary.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ArgBytes

#
func ArgBytes(ev: Event, i: int): Bytes

The bytes of a binary argument.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckCount

#
func AckCount(a: Ack): int

The number of acknowledgement arguments.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckArg

#
func AckArg(a: Ack, i: int): str

The JSON text of one acknowledgement argument.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckStr

#
func AckStr(a: Ack, i: int): str

The acknowledgement argument as a string.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckInt

#
func AckInt(a: Ack, i: int): i64

As an integer.

The example for this item is shown with the ones above: net-socketio-Client.salam

AckFloat

#
func AckFloat(a: Ack, i: int): f64

As a float.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckBool

#
func AckBool(a: Ack, i: int): bool

As a boolean.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckIsBinary

#
func AckIsBinary(a: Ack, i: int): bool

The acknowledgement argument is binary.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckBytes

#
func AckBytes(a: Ack, i: int): Bytes

The bytes of a binary acknowledgement argument.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckValue

#
func AckValue(a: Ack, i: int): value.Value

As an encoding value.

The example for this item is shown with the ones above: net-socketio-Ack.salam

EventFree

#
func EventFree(ev &: Event)

Frees the event's memory.

The example for this item is shown with the ones above: net-socketio-Ack.salam

AckFree

#
func AckFree(a &: Ack)

Frees the acknowledgement's memory.

The example for this item is shown with the ones above: net-socketio-Client.salam

IsConnected

#
func IsConnected(c: Client): bool

The socket is connected.

The example for this item is shown with the ones above: net-socketio-Client.salam

Id

#
func Id(c: Client): str

The socket's id in the namespace.

The example for this item is shown with the ones above: net-socketio-Client.salam

Sid

#
func Sid(c: Client): str

The Engine.IO session id.

The example for this item is shown with the ones above: net-socketio-Client.salam

Namespace

#
func Namespace(c: Client): str

The namespace.

The example for this item is shown with the ones above: net-socketio-Client.salam

Recovered

#
func Recovered(c: Client): bool

After a reconnect, the earlier state was recovered.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Transport

#
func Transport(c: Client): int

The current transport.

The example for this item is shown with the ones above: net-socketio-Manager.salam

LastError

#
func LastError(c: Client): str

The last error.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Buffered

#
func Buffered(c: Client): int

The number of messages waiting for a connection.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Attempts

#
func Attempts(c: Client): int

The number of reconnection attempts.

The example for this item is shown with the ones above: net-socketio-Manager.salam

EndpointOf

#
func EndpointOf(c: Client): Endpoint

The parsed URL of the socket.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Send

#
func Send(c: Client, msg: str): bool

A message event with one string; like send in JavaScript.

The example for this item is shown with the ones above: net-socketio-Ack.salam

PrependAny

#
func PrependAny(c: Client, cb: func(Event))

Like OnAny, but called before the others.

The example for this item is shown with the ones above: net-socketio-Ack.salam

OnAnyOutgoing

#
func OnAnyOutgoing(c: Client, cb: func(Event))

A listener for every message that is sent.

The example for this item is shown with the ones above: net-socketio-Ack.salam

PrependAnyOutgoing

#
func PrependAnyOutgoing(c: Client, cb: func(Event))

Like the function above, before the others.

The example for this item is shown with the ones above: net-socketio-Ack.salam

OffAnyOutgoing

#
func OffAnyOutgoing(c: Client)

Removes the listeners for outgoing messages.

The example for this item is shown with the ones above: net-socketio-Ack.salam

ListenerCount

#
func ListenerCount(c: Client, name: str): int

The number of listeners for an event.

The example for this item is shown with the ones above: net-socketio-Client.salam

HasListeners

#
func HasListeners(c: Client, name: str): bool

The event has listeners.

The example for this item is shown with the ones above: net-socketio-Client.salam

AnyListenerCount

#
func AnyListenerCount(c: Client): int

The number of listeners for every event.

The example for this item is shown with the ones above: net-socketio-Ack.salam

Disconnected

#
func Disconnected(c: Client): bool

The socket is disconnected.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Active

#
func Active(c: Client): bool

The socket is active and reconnects automatically if it drops.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Pending

#
func Pending(c: Client): int

The number of acknowledgements that have not arrived yet.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Queued

#
func Queued(c: Client): int

The number of unread events in the queue.

The example for this item is shown with the ones above: net-socketio-Manager.salam

TransportName

#
func TransportName(c: Client): str

The transport name: websocket or polling.

The example for this item is shown with the ones above: net-socketio-Client.salam

PingInterval

#
func PingInterval(c: Client): int

The ping interval the server set.

The example for this item is shown with the ones above: net-socketio-Manager.salam

PingTimeout

#
func PingTimeout(c: Client): int

The ping timeout.

The example for this item is shown with the ones above: net-socketio-Options.salam

MaxPayload

#
func MaxPayload(c: Client): int

The largest message size the server accepts.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetAuth

#
func SetAuth(c: Client, auth_json: str)

Changes the authentication data for later connections.

The example for this item is shown with the ones above: net-socketio-Manager.salam

AuthOf

#
func AuthOf(c: Client): str

The authentication data.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetReconnection

#
func SetReconnection(m: Manager, enabled: bool)

Turns automatic reconnection on or off.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetReconnectionAttempts

#
func SetReconnectionAttempts(m: Manager, n: int)

The most attempts.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetReconnectionDelay

#
func SetReconnectionDelay(m: Manager, ms: int)

The delay before the first attempt.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetReconnectionDelayMax

#
func SetReconnectionDelayMax(m: Manager, ms: int)

The longest delay.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetRandomizationFactor

#
func SetRandomizationFactor(m: Manager, percent: int)

The random percentage of the delay.

The example for this item is shown with the ones above: net-socketio-Manager.salam

SetTimeout

#
func SetTimeout(m: Manager, ms: int)

The connect timeout.

The example for this item is shown with the ones above: net-socketio-Manager.salam

OptionsOf

#
func OptionsOf(m: Manager): Options

The manager's current options.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Sockets

#
func Sockets(m: Manager): Vector<Client>

The manager's sockets.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Open

#
func Open(m: Manager): bool

Opens the manager's connection.

The example for this item is shown with the ones above: net-socketio-Manager.salam

IsOpen

#
func IsOpen(m: Manager): bool

The manager's connection is open.

The example for this item is shown with the ones above: net-socketio-Manager.salam

ManagerError

#
func ManagerError(m: Manager): str

The manager's last error.

The example for this item is shown with the ones above: net-socketio-Manager.salam

Refused

#
func Refused(c: Client): bool

The server refused the connection to the namespace, for example because the authentication was wrong.

The example for this item is shown with the ones above: net-socketio-Manager.salam

RefusalReason

#
func RefusalReason(c: Client): str

The reason the server gave.

The example for this item is shown with the ones above: net-socketio-Manager.salam