Remote log: Basic end to end ns post/get

Split node recv/sending due to sync
Send to all clients
This commit is contained in:
Oskar Thoren 2019-08-05 13:12:11 +08:00
parent df63bbb77e
commit 52305876d8
No known key found for this signature in database
GPG Key ID: B2ECCFD3BC2EF77E
4 changed files with 47 additions and 1 deletions

View File

@ -12,6 +12,7 @@ setControlCHook(handler)
client.connect("127.0.0.1", Port(6001))
stdout.writeLine("Client connected to name service on 127.0.0.1:6001")
# TODO: Rewrite this to be async so it can send/recv at same time
while true:
stdout.write("> ")
let message: string = stdin.readLine()

View File

@ -0,0 +1,19 @@
import net, os
let client = newSocket()
proc handler() {.noconv.} =
stdout.writeLine("Shutting down connection.")
client.close()
quit 0
setControlCHook(handler)
client.connect("127.0.0.1", Port(6001))
stdout.writeLine("Client connected to name service on 127.0.0.1:6001")
while true:
let receivedMessage: string = client.recvLine()
stdout.writeLine("Message: ", receivedMessage)
client.close()

View File

@ -0,0 +1,21 @@
import net, os
let client = newSocket()
proc handler() {.noconv.} =
stdout.writeLine("Shutting down connection.")
client.close()
quit 0
setControlCHook(handler)
client.connect("127.0.0.1", Port(6001))
stdout.writeLine("Client connected to name service on 127.0.0.1:6001")
# TODO: Rewrite this to be async so it can send/recv at same time
while true:
stdout.write("> ")
let message: string = stdin.readLine()
client.send(message & "\r\L")
client.close()

View File

@ -59,7 +59,7 @@ proc handleMessage(message: Message): Response =
if arg == "POST":
echo("posting: ", data)
currentName = data
return Response(code: OK, data: currentName)
return Response(code: OK, data: "success")
elif arg == "GET":
echo("getting: ", data)
@ -88,7 +88,12 @@ while true:
let resp = handleMessage(parseMessage(message))
# TODO: Respond to client
# XXX: Client is currently non-interactive so sending to other client
# That is, node is split into node_receiving and node_sending
# Sending to all clients:
echo("RESPONSE: ", resp)
for c in clients:
c.send(resp.data & "\r\L")
except TimeoutError:
discard