简体   繁体   English

ZMQ在Linux中不适用于原始套接字,但在Windows中适用

[英]ZMQ doesn't work with the raw socket in Linux but works in Windows

I have a client program written with raw socket communicating with a server. 我有一个用原始套接字编写的与服务器通信的客户端程序。 It uses 'select' to poll the socket descriptor and get the message from the server. 它使用“选择”来轮询套接字描述符并从服务器获取消息。 After getting message, I use a ZMQ socket to send the message out. 收到消息后,我使用ZMQ套接字将消息发送出去。

This works perfectly in windows. 在Windows中完美运行。 But in Linux, after I call the ZMQ 'send' function, I cannot receive message from the server any more. 但是在Linux中,调用ZMQ的“发送”功能后,我再也无法从服务器接收消息。 It seems the raw socket has been affected somehow. 似乎原始套接字已受到某种程度的影响。

The program is a multithread program but I have dealt with ZMQ carefully. 该程序是一个多线程程序,但是我已经仔细处理了ZMQ。 The client program is running in a thread A and the ZMQ socket is only used by that thread A. I think I used ZMQ correctly as it is working well in Windows. 客户端程序在线程A中运行,并且ZMQ套接字仅由该线程A使用。我认为我正确使用了ZMQ,因为它在Windows中运行良好。 But how comes the issue in Linux? 但是Linux中的问题又如何呢?

Anybody knows if this is normal? 有人知道这是否正常吗? I am suspecting this is a ZMQ issue. 我怀疑这是ZMQ问题。 As long as I remove the ZMQ 'send' function, the program works well. 只要删除ZMQ的“发送”功能,该程序就可以正常运行。 Anybody knows how to solve this issue? 有人知道如何解决这个问题吗? and why it is working well in Windows, not in Linux? 以及为什么它在Windows(而不是Linux)中运行良好?


I found it doesn't work even in single thread situation. 我发现即使在单线程情况下它也不起作用。 ZMQ creates more than ten threads automatically for me. ZMQ自动为我创建十多个线程。 I don't use any multithread this time, and the code flow is like this: 这次我不使用任何多线程,代码流如下:

create a raw socket A;
connect to a business server B;
STATE = 1
while (raw socket A is connected){
  if (STATE==1){
    send(Request 1);
  }else if (STATE==2){
    send(Request 2);
  }
  int ret = select(fd + 1, &readSet, &writeSet, &errorSet, &timeout);
  if (ret > 0){
      if (FD_ISSET(fd, &readSet)) {
        char buf[8192];
        int nResult = receive( buf, sizeof(buf));
        if (buf is X){
          zmq.send(messageX)
          STATE=2
        }else if (buf is Y){
          STATE=3
        }else{...}
      }// socket is ready for reading
  }
}

After zmq.send(message), I cannot receive any new message!! zmq.send(message)之后,我无法收到任何新消息! The server side code is closed to me so that I cannot debug from server side. 服务器端代码对我关闭,因此我无法从服务器端进行调试。 If I remove "zmq.send(message)", everything works fine. 如果删除“ zmq.send(message)”,则一切正常。 In Windows, this program works fine too. 在Windows中,该程序也可以正常工作。

Well, it is hard to tell u whats wrong without a code. 好吧,如果没有代码,很难告诉你出了什么问题。 But you should probably look at ZMQ versions in Linux and Windows because the "formats of sending" etc can differ between versions and stuff that works in one version will not in another. 但是您可能应该查看Linux和Windows中的ZMQ版本,因为不同版本之间的“发送格式”等可能不同,而在一个版本中可用的内容在另一个版本中不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM