Created
August 22, 2018 15:06
-
-
Save pigmej/31e0cd9ba7fcdd4a089a0ee99dce4b5e 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 asyncnet, asyncdispatch | |
var sock: AsyncSocket | |
proc looper() {.async.} = | |
while true: | |
echo "Waiting for data" | |
var data = await sock.recvLine() | |
if data.len == 0: | |
echo "No data, disconnected(?)" | |
return | |
echo "Got data ", data | |
if isMainModule: | |
proc demo() {.async.} = | |
sock = newAsyncSocket() | |
await sock.connect("127.0.0.1", 2341.Port) | |
echo "post connect" | |
asyncCheck looper() | |
echo "post looper" | |
await sleepAsync(100) | |
sock.close() | |
echo "Closed" | |
await sleepAsync(10000) | |
waitFor demo() | |
runForever() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment