mirror of
https://github.com/codex-storage/nim-websock.git
synced 2025-01-22 16:39:19 +00:00
3e1599d790
* moving files around * wip * wip * move tls example into server example * add tls functionality * rename * rename * fix tests * move extension related files to own folder * use trace instead of debug * export extensions * rework partial frame handling and closing * rework status codes as distincts * logging * re-enable extensions processing for frames * enable all test for non-tls server * remove tlsserver * remove offset to mask - don't think we need it * pass sessions extensions when calling send/recv * adding encode/decode extensions flow test * move server/client setup to helpers * proper frame order execution on decode * fix tls tests
46 lines
936 B
Nim
46 lines
936 B
Nim
import pkg/[
|
|
chronos,
|
|
chronicles,
|
|
stew/byteutils]
|
|
|
|
import ../ws/ws
|
|
|
|
proc main() {.async.} =
|
|
let ws = when defined tls:
|
|
await WebSocket.connect(
|
|
"127.0.0.1",
|
|
Port(8888),
|
|
path = "/wss",
|
|
flags = {TLSFlags.NoVerifyHost, TLSFlags.NoVerifyServerName})
|
|
else:
|
|
await WebSocket.connect(
|
|
"127.0.0.1",
|
|
Port(8888),
|
|
path = "/ws")
|
|
|
|
trace "Websocket client: ", State = ws.readyState
|
|
|
|
let reqData = "Hello Server"
|
|
while true:
|
|
try:
|
|
await ws.send(reqData)
|
|
let buff = await ws.recv()
|
|
if buff.len <= 0:
|
|
break
|
|
|
|
let dataStr = string.fromBytes(buff)
|
|
trace "Server Response: ", data = dataStr
|
|
|
|
assert dataStr == reqData
|
|
break
|
|
except WebSocketError as exc:
|
|
error "WebSocket error:", exception = exc.msg
|
|
raise exc
|
|
|
|
await sleepAsync(100.millis)
|
|
|
|
# close the websocket
|
|
await ws.close()
|
|
|
|
waitFor(main())
|