Created
May 18, 2019 23:18
-
-
Save enthus1ast/19a472de473e1049ec954f9cc946068c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncdispatch, asyncnet | |
type | |
Server = ref object | |
socket: AsyncSocket | |
proc newServer(): Server = | |
Server(socket: newAsyncSocket()) | |
proc loop(server: Server, port = 7920) {.async.} = | |
server.socket.bindAddr(Port(port), "0.0.0.0") | |
server.socket.listen() | |
while true: | |
let (netAddr, clientSocket) = await server.socket.acceptAddr() | |
# echo await clientSocket.recvLine() | |
await clientSocket.send("HTTP/1.1 200 OK\n\nTest") | |
clientSocket.close() | |
var server = newServer() | |
echo "Staring server..." | |
waitFor loop(server) | |
################################################### | |
[david@eb fit]$ ncat 127.0.0.1 7920 | |
HTTP/1.1 200 OK | |
Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment