nim-websock/examples/tlsclient.nim
Dmitriy Ryajov 64da1a4344
Rework http (#38)
* wip

* wip

* move http under ws folder

* use asyctest

* wip

* wip

* rework response sending

* make example work with latest changes

* wip request/response

* misc

* fix example to use new http layer

* pass tls flags to client

* more cleanup

* unused imports

* more unsused imports

* better headers

* add helpre sendError

* export sendError

* attach selected proto to session

* move proto to session

* handle unsupported version

* fix tests

* comment out for now

* fix utf8 tests

* allow tests to be ran in tls

* misc

* use Port type

* add tls flags

* better api

* run tls tests

* fix tests on windows

* allow running tests with tls

* mic

* wip

* fix autobahn ci

* handle close

* cleanup

* logging and error handling

* remove old stream
2021-05-31 20:39:14 -06:00

36 lines
891 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:
debug "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())