mirror of
https://github.com/codex-storage/nim-websock.git
synced 2025-02-02 13:53:21 +00:00
6b76bd8261
* Update http to use chronos http. * Implement TLS in websocket. * Add webscoket TLS test. * Minor nit. * Add TLS test file. * Update http to use chronos http. (#6) * Update http to use chronos http. * Add stream.nim file. * Address comments. * Fix CI failure. * Minor change. * Address comments. * Fix windows CI failing test. * minor cleanup * spacess * more idiomatic connect * use stew/base10 Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> * Implement TLS in websocket. * Minor nit. * merge master * wip * Update http to use chronos http. (#6) * Update http to use chronos http. * Add stream.nim file. * Address comments. * Fix CI failure. * Minor change. * Address comments. * Fix windows CI failing test. * minor cleanup * spacess * more idiomatic connect * use stew/base10 Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> * Update http to use chronos http. * Implement TLS in websocket. * Minor nit. * Update http to use chronos http. (#6) * Update http to use chronos http. * Add stream.nim file. * Address comments. * Fix CI failure. * Minor change. * Address comments. * Fix windows CI failing test. * minor cleanup * spacess * more idiomatic connect * use stew/base10 Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> * Implement TLS in websocket. * Minor nit. * add testing keys * wip * fix test * wip * remove eth dep and add skipdirs * fix package structure * fix deps * check nim version * Fix CI failure. * Don't call `ws.stream.closeWait()` * always close both ends to complete the sequence * misc * don't fail on close * Fix windows CI. * fix linux x86 builds * use consistent connect pattern * move keys to better place * return dumbResponse * small cleanup Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
35 lines
888 B
Nim
35 lines
888 B
Nim
import pkg/[chronos,
|
|
chronos/streams/tlsstream,
|
|
chronicles,
|
|
stew/byteutils]
|
|
|
|
import ../ws/ws
|
|
|
|
proc main() {.async.} =
|
|
let ws = await WebSocket.tlsConnect(
|
|
"127.0.0.1",
|
|
Port(8888),
|
|
path = "/wss",
|
|
protocols = @["myfancyprotocol"],
|
|
flags = {NoVerifyHost,NoVerifyServerName})
|
|
debug "Websocket client: ", State = ws.readyState
|
|
|
|
let reqData = "Hello Server"
|
|
try:
|
|
echo "sending client "
|
|
await ws.send(reqData)
|
|
let buff = await ws.recv()
|
|
if buff.len <= 0:
|
|
break
|
|
let dataStr = string.fromBytes(buff)
|
|
debug "Server:", data = dataStr
|
|
|
|
assert dataStr == reqData
|
|
return # bail out
|
|
except WebSocketError as exc:
|
|
error "WebSocket error:", exception = exc.msg
|
|
|
|
# close the websocket
|
|
await ws.close()
|
|
waitFor(main())
|