Remove cruft, fix indentation
Anirudh Oppiliappan x@icyphox.sh
Mon, 27 Jul 2020 11:23:23 +0530
1 files changed,
5 insertions(+),
17 deletions(-)
jump to
M
src/wsabi.nim
→
src/wsabi.nim
@@ -11,12 +11,6 @@ json,
uri -# var -# server = newAsyncHttpServer() -# remote: WebSocket -# client: WebSocket -# clients: newSeq[WebSocket]() - type Client = object ws: WebSocket@@ -27,18 +21,13 @@ server = newAsyncHttpServer()
client: Client clients = newSeq[Client]() -# proc connectRemote(remote: WebSocket, host: string) {.async.} = -# remote = await newWebSocket(host, protocol = "xmpp") -# let (address, port) = remote.tcpSocket.getPeerAddr() -# echo fmt"connected to {address}:{port.int}" proc commRemoteClient(c: Client) {.async.} = ## Fetch from remote and send to client while c.remote.readyState == Open: - echo "yes open" var data = await c.remote.receiveStrPacket() echo "from remote: ", data - await c.ws.send(data + await c.ws.send(data) proc localServer(req: Request) {.async, gcsafe.} = ## Listen on localhost:PORT/ws@@ -59,17 +48,17 @@ clients.add client
try: while client.ws.readyState == Open: - # TODO: don't hardcode these replacements + let clientAddress = client.ws.tcpSocket.getPeerAddr()[0] var packet = await client.ws.receiveStrPacket() - repacket = packet.replace("127.0.0.1", by=bits.hostname) + repacket = packet.replace(clientAddress, by=bits.hostname) echo "from local: " & repacket await client.remote.send(repacket) echo "sent local packet" asyncCheck commRemoteClient(client) - except WebSocketError: - echo "client closed socket: ", getCurrentExceptionMsg() + except WebSocketError as e: + echo "client closed socket: ", e.msg ## Health check endpoint ## The 'uri' can be either 'ws' or 'http'.@@ -134,7 +123,6 @@ when isMainModule:
parseArgs() echo fmt"local server running at ws://127.0.0.1:{localPort}/ws" asyncCheck server.serve(Port(localPort), localServer) - echo "calling commRemoteClient" runForever()