Troubles with zmq_bind() in ZeroMQ binding for MQL

2020-06-27 09:06发布

I am working on MT4 and used wrapper mql4zmq.dll as given in link

https://github.com/AustenConrad/mql4zmq

As I have followed all instruction and successfully loaded DLL as well as lib file at specific locations from pre-compiled. But it can not bind or connect with socket through zmq_connect(,) or zmq_bind(,). Please some one help me to solve this problem. I am posting my code here

// Include the libzmq.dll abstraction wrapper.
#include <mql4zmq.mqh>

//+------------------------------------------------------------------+
//| variable definitions                                             |
//+------------------------------------------------------------------+
int speaker,listener,contextt;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   int major[1];int minor[1];int patch[1];
   zmq_version(major,minor,patch);
   Print("Using zeromq version " + major[0] + "." + minor[0] + "." + patch[0]);

   Print(ping("Hello World"));

   Print("NOTE: to use the precompiled libraries you will need to have the Microsoft Visual C++ 2010 Redistributable Package installed. To Download: http://www.microsoft.com/download/en/details.aspx?id=5555");

   contextt = zmq_init(1);
   speaker = zmq_socket(contextt, ZMQ_PUB);
   listener = zmq_socket(contextt, ZMQ_SUB);

   // Subscribe to the command channel (i.e. "cmd").  
   // NOTE: to subscribe to multiple channels call zmq_setsockopt multiple times.
   zmq_setsockopt(listener, ZMQ_SUBSCRIBE, ""); 

   if (zmq_bind(speaker,"tcp://127.0.0.1:5555") == -1) 
   {
      Print("Error binding the speaker!");
      return(-1);  
   } 

There is problem in

if ( zmq_bind( speaker, "tcp://127.0.0.1:5555" ) == -1 )

It returns -1 and does not bind.

I have tried every possible thing to solve this mystery but failed.

Please let me know if I am mistaken!!!

1条回答
来,给爷笑一个
2楼-- · 2020-06-27 09:44

Yes, address/port-in use may block .bind() / .connect()

As solved in the comments above, there is another post with a similar solution of the same root-cause why the well-formed ZeroMQ-code was still not able to .bind()

Address/port release/re-use is O/S-dependent resource-management issue. Be carefull once developing for a production-grade operations.

查看更多
登录 后发表回答