Okay as a prerequisite I am new to the language and am likely doing something incorrectly.
I am using the Sockets module from the standard library.
I am writing a client side julia program that needs to read two Float64s from a server and then write two Float64s to a server every user defined timestep.
Since IO blocks I read via a remotecall and then (at the moment) I write in my main process. After I write I experience a halt with no error or exception.
The culprit is the eof() function called in my remote call. If I remove it then I do not get an error. But why? I’m aware eof() blocks but why is that affecting my main thread? Is this because I’m attempting to read and write to the same stream?
The lack of an immediate error is a bit of an issue.
Here is the function I remote call:
function ReadAsync(sock::Sockets.TCPSocket)
try
## Ensures we read the last entry in the socket buffer
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
Here is my main function
function main()
clientTime = 0.0
lastHeardTimeout = 10.0
dt = 8.0
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
while true
elapsed = time() - startTime
if elapsed > dt
clientTime = clientTime + dt
# I would normally check for reads here!
elapsedHeardTime = time() - lastHeardTime
if (elapsedHeardTime < lastHeardTimeout && iswritable(sock))
println("Socket Writable.")
numBytes = write(sock, clientTime)
println("Socket Written.")
# It halts here. "Shown" is never reached.
println("Shown.")
write(sock, funcVal)
else
println("I haven't heard from the server in awhile...")
end
startTime = time()
end
end
catch e
println("caught it $e")
close(sock)
end
close(sock)
end