import websocket, asyncnet, asyncdispatch
let ws = waitFor newAsyncWebsocketClient("echo.websocket.org",
Port 80, "/?encoding=text", ssl = false)
echo "connected!"
proc reader() {.async.} =
while true:
let read = await ws.readData()
echo "read: ", read
proc ping() {.async.} =
while true:
await sleepAsync(6000)
echo "ping"
await ws.sendPing(masked = true)
asyncCheck reader()
asyncCheck ping()
runForever()
net, asyncdispatch, asyncnet, base64, times, strutils, securehash, nativesockets, streams, tables, oids, uri, shared, private/hex
WebsocketUserAgent = "websocket.nim (https://github.com/niv/websocket.nim)"
-
proc newAsyncWebsocketClient(host: string; port: Port; path: string; ssl = false;
additionalHeaders: seq[(string, string)] = @[];
protocols: seq[string] = @[];
userAgent: string = WebsocketUserAgent;
ctx: SslContext = defaultSslContext): Future[
AsyncWebSocket] {.raises: [FutureError], tags: [TimeEffect, RootEffect]
.}
-
Create a new websocket and connect immediately. Optionally give a list of protocols to negotiate; keep empty to accept the one the server offers (if any). The negotiated protocol is in AsyncWebSocket.protocol.
proc newAsyncWebsocketClient(uri: Uri;
additionalHeaders: seq[(string, string)] = @[];
protocols: seq[string] = @[];
userAgent: string = WebsocketUserAgent;
ctx: SslContext = defaultSslContext): Future[
AsyncWebSocket] {.raises: [FutureError], tags: [TimeEffect, RootEffect]
.}
-
proc newAsyncWebsocketClient(uri: string;
additionalHeaders: seq[(string, string)] = @[];
protocols: seq[string] = @[];
userAgent: string = WebsocketUserAgent;
ctx: SslContext = defaultSslContext): Future[
AsyncWebSocket] {.raises: [FutureError], tags: [TimeEffect, RootEffect]
.}
-
proc newAsyncWebsocket(host: string; port: Port; path: string; ssl = false;
additionalHeaders: seq[(string, string)] = @[];
protocols: seq[string] = @[];
userAgent: string = WebsocketUserAgent;
ctx: SslContext = defaultSslContext): Future[AsyncWebSocket] {.
deprecated, raises: [FutureError], tags: [TimeEffect, RootEffect]
.}
-
proc newAsyncWebsocket(uri: Uri; additionalHeaders: seq[(string, string)] = @[];
protocols: seq[string] = @[];
userAgent: string = WebsocketUserAgent;
ctx: SslContext = defaultSslContext): Future[AsyncWebSocket] {.
deprecated, raises: [FutureError], tags: [TimeEffect, RootEffect]
.}
-
proc newAsyncWebsocket(uri: string;
additionalHeaders: seq[(string, string)] = @[];
protocols: seq[string] = @[];
userAgent: string = WebsocketUserAgent;
ctx: SslContext = defaultSslContext): Future[AsyncWebSocket] {.
deprecated, raises: [FutureError], tags: [TimeEffect, RootEffect]
.}
-