Hello guys.
Is there any way to find out if async socket proc connect() has established a connection or not - it just returns Future[void] either way - or a proper way to handle refused connections?
My program crashes when I call
await socket.recvLine()
for a socket where asyncCheck socket.connect(serverAddress, port.Port)
did not established a connection i.e. random IP, but it works ok when I connect to my server which listens.
I've tried to catch an Exception and OSError (shown in traceback) but it didn't work. Shown errors:
Error: unhandled exception: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.
Exception message: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.
Exception type: [OSError]
But await works only inside an async proc
were as asyncCheck can be used like this:
when isMainModule :
asyncCheck mastercon()
runForever()
How can we do:
when isMainModule :
await mastercon()
runForever()
You need to use waitFor instead of await if you want to run {.async.} proc in non {.async.} context.
when isMainModule :
waitFor mastercon()