I would like to read the first message out of a websocket as soon as it arrives, but also I want to close the connection if nothing arrives within a second.
How can I do that?
task = @async HTTP.WebSockets.listen("127.0.0.1", UInt16(9091)) do ws while !eof(ws) cmd = JSON.parse(String(readavailable(ws))) println(cmd) end end
readavailable function does not have a timeout parameter. If I call it then it may block indefinitely. The
eof function does not block at all, so it cannot be used to “wait for the first message”.
So how do I do this?
Background info: I want to create a server that can respond quickly, closes the connection if there is no communication for a while.