0

I have the need to communicate two applications , one server in C ++ and one c # client .

I'm trying to use 0MQ on the server and the binder C # NetMq . I can make the connect from the client and to send a message from the client to the server but not the other . The client waits and does not receive the sending by the server.

Some examples?

Server:

try
{
zmq::context_t context (1);
zmq::socket_t socket(context, ZMQ_PAIR);
socket.bind ("tcp://*:5556");
zmq::message_t request;
// just once
for(;;)
{
    zmq::message_t request;
    socket.recv (&request);
    std::cout << "Received" << std::endl;   
    std::string msg_str(static_cast<char*>(request.data()), request.size());    
    std::cout << msg_str << std::endl;

    zmq::message_t reply (5);
    memcpy (reply.data (), "Hello", 5);
    boost::this_thread::sleep_for(boost::chrono::milliseconds(2000));
    socket.send(reply);
}

Client:

 using (var requestSocket = new RequestSocket(">tcp://192.168.70.150:5556"))
 {
     Console.WriteLine("requestSocket : Sending 'Hello'");
     requestSocket.SendFrame("Hello");

     var message = requestSocket.ReceiveFrameString();

    Console.WriteLine(message);

  }

This is a trivial example of sending and response that I'm trying to implement and then expand .

1 Answers1

1

Problems with the code:

  • PAIR sockets in ZeroMQ are for inter-thread communication with inproc transport, you shouldn't use them with tcp
  • On the .Net side you're using REQ socket, which is not compatible with PAIR

Switching to ZMQ_REP socket on the C++ should solve your issue. Here's the detailed documentation on socket types, the ZMQ Guide has very good description on communication patters built on these sockets.

Gyorgy Szekely
  • 2,654
  • 3
  • 23
  • 32