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

555 views Asked by At

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.

This works perfectly in windows. But in Linux, after I call the ZMQ 'send' function, I cannot receive message from the server any more. It seems the raw socket has been affected somehow.

The program is a multithread program but I have dealt with ZMQ carefully. 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. But how comes the issue in Linux?

Anybody knows if this is normal? I am suspecting this is a ZMQ issue. As long as I remove the ZMQ 'send' function, the program works well. Anybody knows how to solve this issue? and why it is working well in Windows, not in Linux?


I found it doesn't work even in single thread situation. ZMQ creates more than ten threads automatically for me. 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!! 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. In Windows, this program works fine too.

1

There are 1 answers

1
user2123079 On

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.