I have a server and a client, both written in Julia. I’m using the Sockets module from the standard Julia library.
I have an issue on the client where I connect to a server and read from a server. I read from the socket in a separate process via a remotecall. In the main thread I then send data to the server.
I experience a soft lock after writing. It appears as though the culprit is calling eof() in the remote call (which blocks) but the result is odd. There doesn’t seem to be an exception or error. It also doesn’t seem to be blocked by any IO as it appears to send() successfully. It just seems to halt directly after I read (and then print some debug info)
For the sake of this error I have simplified the implementation to demonstrate what’s happening
This is the serverside. I basically send data every 0.5 seconds
import Sockets import Future import Distributed function main() server = Sockets.listen(50009) sock = Sockets.accept(server) dt = 0.5 startTime = time(); while (true) elapsed = time() - startTime if elapsed > dt write(sock, 1) startTime = time() end end end main()
Then client side, where I read and send data every 0.5 seconds. I read via a remotecall
import Sockets import Future import Distributed function ReadAsync(sock::Sockets.TCPSocket) try println(" ASYNC Begin.") timestamp = 0.0 funcVal = 0.0 arr = Float64 while !eof(sock) # push!(arr, read(sock, Float64)) end println(" ASYNC END.") return timestamp, funcVal catch e println("caught it $e") end end function main() clientTime = 0.0 lastHeardTimeout = 10.0 dt = 0.5 timestamp = 0.0 funcVal = 0.0 sock = Sockets.connect("localhost", 50009); println("Ready and waiting...") # Start a thread that checks for reads. r = remotecall(ReadAsync, 1, sock) startTime = time(); lastHeardTime = time(); try number = 0.0 while true elapsed = time() - startTime if elapsed > dt clientTime = clientTime + dt elapsedHeardTime = time() - lastHeardTime if (elapsedHeardTime < lastHeardTimeout && iswritable(sock)) println("Socket Writable.") numBytes = write(sock, clientTime) println("Socket Wrritten.") println(" IT HALTS HERE !!!!") println("Continues") else println("I haven't heard from the server in awhile...") end startTime = time() # the sync waits for the previous async to be finished before starting the next iteration end end catch e println("caught it $e") close(sock) end close(sock) end main()
I’m obviously doing something wrong here. But my lack of experience and lack of immediate error is making me a bit stuck.