I'm trying to work out how to exchange data between two (separate) Julia instances, and I was thinking a socket file + serialize
/deserialize
may be a nice solution. However, I can't quite work out how to get it to work. This is what I've got so far:
Julia 1
using Sockets
s = Sockets.listen("/run/user/1000/jltest.sock") # => PipeServer
Julia 2
using Sockets
s = Sockets.connect("/run/user/1000/jltest.sock") # => PipeEndpoint
With "Julia 2" I can run write(s, "testing")
, however I can't work out how to receive anything in "Julia 1". Furthermore, is there any way I might be able to make this bidirectional?
as with any server/client, you first have to accept
a connection on the server side
JL1
julia> s = listen("/run/user/1000/jltest.sock")
Sockets.PipeServer(RawFD(20) active)
julia> s
Sockets.PipeServer(RawFD(20) active)
julia> con = accept(s)
Base.PipeEndpoint(RawFD(21) open, 0 bytes waiting)
julia> readline(con)
"hello!"
julia> println(con, "This is JL1")
JL2
julia> s = connect("/run/user/1000/jltest.sock")
Base.PipeEndpoint(RawFD(20) open, 0 bytes waiting)
julia> println(s, "hello!")
julia> readline(s)
"This is JL1"
I use RemoteREPL.jl for this. Despite’s the name, you dont need a REPL active. Its pretty nice, might be worth checking if it fits your needs
As this opens a Unix Domain Socket (or a Named Socket on windows), this is already bidirectional - it's a pipe after all
Does RemoteREPL actually support sending stuff between the instances?
Yup
I used it to move a multi gigabyte array of named tuples today actually
Ah lovely, I might need to give RemoteREPL a look then.
Transfer variables between processes with
@remote
:heart_eyes: this looks like exactly what I was working towards
Ah, would be nice if it supported using socket files, oh well, I can probably pick and spare a port.
Yeah. That’d be a nice feature addition to the package.
Looks like there’s already an issue for it: https://github.com/c42f/RemoteREPL.jl/issues/31
Last updated: Nov 22 2024 at 04:41 UTC