I am trying to establish a socket that listens for requests. Unfortunately, due to a combination of sparse documentation and my lack of familiarity with networking, I am unable to accomplish this through normal means.
This part of the package code seems to suggest that I can configure certain behaviors in ZQM. However, I am not sure how to do it. Here is my best attempt:
using ZMQ
ctx = Context()
s1 = Socket(ctx, REP)
setproperty!(s1, :set_tcp_keepalive, 1)
which results in the following error:
ERROR: Socket has no field set_tcp_keepalive
Stacktrace:
[1] setproperty!(::Socket, ::Symbol, ::Int64) at /home/dfish/.julia/packages/ZMQ/KdNw3/src/sockopts.jl:133
[2] top-level scope at none:0
Would someone be willing to provide a MWE example showing how to continuously listen for requests?
I was able to figure out how to establish continuous communication between a client and server. I will post the code below in case it is useful for someone in the future.
Nonetheless, it would be useful to have some instruction for changing the configuration via setproperty!
. This information is not available in the ZMQ documentation.
using ZMQ
function server_listen(server)
#setproperty!(s1, :set_tcp_keepalive, 1)
while true
msg = recv(server, String)
println("Server received: ", msg)
send(server, "Client request processed.")
end
end
function client_send(client)
for i in 1:1000
send(client, string("Client request # ", i))
msgin = recv(client, String)
println("Request status: ", msgin)
end
end
# initialize connections
ctx = Context()
server = Socket(ctx, REP)
bind(server, "tcp://127.0.0.1:5555")
client = Socket(ctx, REQ)
connect(client, "tcp://127.0.0.1:5555")
# start server
@async server_listen(server)
# stress test
[client_send(client) for _ in 1:5]
close(server)
close(client)
1 Like