Q :
"... the problem i know it stoped when i try to connect to server through port 5555 and i do not get any reply or confirm that it connected"
A :
Well,
the ZeroMQ REQ/REP
-session is not easy to connect / disconnect and re-enter the loop.
Why?
ZeroMQ REQ
-side asks ( by a .send()
), and expects the REP
-side to indeed answer ( doing first .recv()
and sending an answer, using .send()
). In case this distributed-FSA ceases to follow the two-step dance, an unsalvageable mutual-deadlock happens ( sooner or later ... )
As a starting template, this may help solve not to fall into hanging endless on blocking form of the .recv()
-method.
...
try:
print ( "INF: REP-side is going to .bind()" )
socket.bind( "tcp://A.B.C.D:5555" )
print ( "INF: REP-side was able to .bind()" )
except:
print ( "EXC: REP-side on going to .bind()" )
exit()
...
while True:
try:
print ( "INF: REP-side is going to .poll()" )
while 0 == socket.poll( timeout = POLL_WAIT_TIME_MSEC,
flags = zmq.POLLIN
):
print ( "NOP: REP-side is going to .sleep()" )
time.sleep( POLL_LOOP_SLEEP_TIME )
print ( "INF: REP-side is going to .poll() again" )
print ( "INF: REP-side is ready to .recv()" )
content = json.loads( socket.recv().decode( 'UTF-8' ) )
print ( "INF: REP-side is recvd a message" )
post_slug = content['post_slug']
image_slug = content['image_slug']
refer = content['refer']
links = content['links']
result = f"{content},{post_slug},{image_slug},{refer},{links}"
print ( "INF: REP-side is ready to .send()" )
socket.send_string( result )
except Exception as e:
print ( "EXC: something happened", repr( e ) )
time.sleep(1)
Inventory of further problems :
receiving side has to cope with being able to handle cases, when (for whatever reasons) the .recv()
will face a multipart message in incoming Queue ( the code above silently assumes this will never happen, yet a handling loop shall be added, so as to solve any such case, otherwise one will never be able to keep the flow working - there can never be a .send()
, unless all "tail"-frames, from the .recv()
-ed, have been all fully .recv()
-ed too )
configuring the sockets may help make the { .connect() | .disconnect() }
-relations from among 1-or-more clients survivable ( .setsockopt( zmq.IMMEDIATE, True ), zmq.CONFLATE, ...
and other attributes may help increase connection-level robustness and/or performance ( if needed ) )
last but not least, a socket_monitor()
-instance is able to provide additional monitoring/signalling level-of-details, if needed to react/respond to connection-level events