Skip to content

Commit

Permalink
lookup localhost ip in precompile bind
Browse files Browse the repository at this point in the history
not all versions of libzmq support binding to a hostname
  • Loading branch information
minrk committed May 28, 2024
1 parent bae8c69 commit 0e53f7c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/ZMQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ import PrecompileTools: @compile_workload

s2=Socket(REQ)

ZMQ.bind(s1, "tcp://localhost:*")
# zmq < 4.3.5 can only bind to ip address or network interface, not hostname
localhost_ip = Sockets.getaddrinfo("localhost")
ZMQ.bind(s1, "tcp://$(localhost_ip):*")
# Strip the trailing null-terminator
last_endpoint = s1.last_endpoint[1:end - 1]
# Parse the port from the endpoint
port = parse(Int, split(last_endpoint, ":")[end])
ZMQ.connect(s2, "tcp://localhost:$(port)")
ZMQ.connect(s2, "tcp://$(localhost_ip):$(port)")

msg = Message("test request")

Expand Down

0 comments on commit 0e53f7c

Please sign in to comment.