2

我正在使用 MT4 并使用mql4zmq.dll链接中给出的包装器

https://github.com/AustenConrad/mql4zmq

因为我已遵循所有说明并成功加载DLL以及lib预编译的特定位置的文件。但它不能通过bindconnect与socketzmq_connect(,)zmq_bind(,)。请有人帮我解决这个问题。我在这里发布我的代码

// 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);  
   } 

里面有问题

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

它返回-1而不是bind

我已经尝试了所有可能的方法来解开这个谜团,但失败了。

如果我记错了请告诉我!!!

4

1 回答 1

0

是的,address/port-in use 可能会阻塞.bind() / .connect()

正如上面评论中所解决的那样,还有 另一篇文章具有相同的根本原因的类似解决方案,为什么格式良好的 ZeroMQ 代码仍然无法.bind()

地址/端口释放/重用是依赖于操作系统的资源管理问题。为生产级操作开发时要小心。

于 2015-09-17T00:51:51.657 回答