Stream: helpdesk (published)

Topic: Use socket file to transfer data


view this post on Zulip Timothy (Feb 17 2023 at 06:35):

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?

view this post on Zulip Sukera (Feb 17 2023 at 07:13):

as with any server/client, you first have to accept a connection on the server side

view this post on Zulip Sukera (Feb 17 2023 at 07:14):

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"

view this post on Zulip Mason Protter (Feb 17 2023 at 07:15):

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

view this post on Zulip Sukera (Feb 17 2023 at 07:16):

As this opens a Unix Domain Socket (or a Named Socket on windows), this is already bidirectional - it's a pipe after all

view this post on Zulip Sukera (Feb 17 2023 at 07:17):

Does RemoteREPL actually support sending stuff between the instances?

view this post on Zulip Mason Protter (Feb 17 2023 at 07:17):

Yup

view this post on Zulip Mason Protter (Feb 17 2023 at 07:18):

I used it to move a multi gigabyte array of named tuples today actually

view this post on Zulip Timothy (Feb 17 2023 at 07:23):

Ah lovely, I might need to give RemoteREPL a look then.

view this post on Zulip Timothy (Feb 17 2023 at 07:24):

Transfer variables between processes with @remote

:heart_eyes: this looks like exactly what I was working towards

view this post on Zulip Timothy (Feb 17 2023 at 07:25):

Ah, would be nice if it supported using socket files, oh well, I can probably pick and spare a port.

view this post on Zulip Mason Protter (Feb 17 2023 at 17:07):

Yeah. That’d be a nice feature addition to the package.

view this post on Zulip Mason Protter (Feb 17 2023 at 17:09):

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