I’m trying setup communication between two Julia processes using
TCPSocket, but I’m having some issues making it work reliably and I’m not sure my design is correct (I don’t know much about networking).
What I do essentially is to start a server on each process that listen to incoming data and process it:
function start_server() port, server = listenany(8000) @async begin while true sock = accept(server) @async process_client(sock) end end port, server end function process_client(sock) while isopen(sock) data = try deserialize(sock) catch err ... end response = process_message(data...) serialize(sock, response) end end
And then to send data from process1 to process2 I do something like:
serialize(process1, data) response = deserialize(process1)
I’ve got more
try .. catch blocks to deal with errors but I’m still getting some issues, for example when trying to deserialize data types that are not defined on one of the process (I know that should fail, I just want it to fail gracefully).
Is that design correct ? I looked a bit at Distributed code but it’s rather complicated. I see it uses two streams (one to read one to write) instead of one, is that a better way to do it?
Also is there any other examples/resources around?