mirror of
https://github.com/vacp2p/research.git
synced 2025-02-24 04:08:15 +00:00
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:
parent
df63bbb77e
commit
52305876d8
@ -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()
|
||||
|
19
remote_log/node_receiving.nim
Normal file
19
remote_log/node_receiving.nim
Normal 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()
|
21
remote_log/node_sending.nim
Normal file
21
remote_log/node_sending.nim
Normal 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()
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user