-1

I have a ZeroMQ Server set up in MQL4 (a c++ like language), and a ZeroMQ Client in Python. A connection made of PUSH/PULL-sockets works well, but when I try to send requests from Python using a REQ-socket to a ZeroMQ REP-socket, it doesn't receive anything. Here is the Python code :

    reqSocket.connect( "tcp://locahost:%d" % REQ_PORT )

    jsonMsg = json.dumps( requestMessage )

    socket.send_string( jsonMsg )
    print( "Sent a message" )

    response = socket.recv()
    print( "received a message" )

Here is the MQL4 code :

    repSocket.bind( StringFormat( "%s://%s:%d",
                                   ZEROMQ_PROTOCOL,
                                   HOSTNAME,
                                   REP_PORT
                                   )
                    );
    repSocket.recv( request, true );

    if( request.size() > 0 ) {

        string reply = MessageHandler( request );
        Print( reply );
        repSocket.send( reply );
        }

I have no doubt the sockets are connected right, because I have PUSH/PULL sockets connected the same way and it works fine.

user3666197
  • 1
  • 6
  • 50
  • 92
blennd
  • 71
  • 6

2 Answers2

-1

Q : "Why a ZeroMQ Server does not receive any requests from Client?"

Because the source code does not send any :

reqSocket.connect( "tcp://locahost:%d" % REQ_PORT )
#^^^^^^^^._____________________________________________________SOCKET.connect()-s
jsonMsg = json.dumps( requestMessage )
pass;      socket.send_string( jsonMsg ); print( "Sent" )
response = socket.recv();
#          ^^^^^^.____________________________________other_one_.{send|recv}()-es

socket.send_string( jsonMsg ) . Isn't this sending the request? BTW socket = reqSocket (passed as a variable inside the function so that's not the issue) – blennd 1 hour ago

What a lecture !

@blennd if you argue with pieces of information, that you did not post in the MCVE, you perhaps despise others, who sponsor their time and knowledge to try to help you. Quite an antipattern for this Community and quite the opposite to the Site Culture.


The next candidate - if a socket-object is actually a secretly re-dressed the reqSocket-instance :

perhaps, the .connect()-method ought 've got called with a bit more care taken,
using a "tcp://locaLhost:%d" % REQ_PORT, ought it not?

fully ready to hear, that your DNS-tables have already been set to and active to smoothly xlate a locahost symbolic host-name into the localhost and many other symbolic names,
just from this side of the Pacific, it seemed obvious, at least so far

:o)

user3666197
  • 1
  • 6
  • 50
  • 92
  • socket.send_string( jsonMsg ) . Isn't this sending the request? BTW socket = reqSocket (passed as a variable inside the function so that's not the issue) – blennd May 07 '20 at 21:57
-2

my code:

    Context *context;
    Socket *rec;

    string ZEROMQ_PROTOCOL = "tcp";
    string HOSTNAME = "127.0.0.1";
    #define REP_PORT 55555
...
   context=new Context();   // <-- mayby u a forget
   rec= new Socket(context,ZMQ_REQ);
   rec.setReceiveTimeout(500);
   cConnect = StringFormat( "tcp://%s:%s",HOSTNAME,REP_PORT);
   rec.connect(cConnect);