0

I am making an application that works in three different parts. One server running in C ++ and two clients running in C # and Python. The client connects to the server and sends a message.

To do this I have opted for ZeroMQ.

Because this is a POC, the code is simple.

Server Code (C++) (cppzmq)

zmq::context_t context{ 1 };
zmq::socket_t socket{ context, zmq::socket_type::rep };
socket.bind("tcp://*:5555");
zmq::message_t request;
socket.recv(request, zmq::recv_flags::none);

Python Client (pyzm)

context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
socket.send(b"Hello")

C# client (NetMQ)

using(var socket =  new RequestSocket())
{
    socket.Connect("tcp://localhost:5555");
    byte[] msg = Encoding.ASCII.GetBytes("HEllo");
    socket.SendFrame(msg);
 }

The connection between the Python client and the server is successful and the server receives the message sent by the client. But the connection between C # client and server is not correct. On the C # side it is assumed that you have successfully connected and transmitted the message, but the server does not reflect any changes (as if you did not receive a call).

What can be the cause?

  • in `NetMq` `socket.SendFrame` seem to be supporting string type. Give it a go. `socket.SendFrame("HEllo")`. Ref : https://zeromq.org/get-started/?language=csharp&library=netmq# – Supun De Silva Jul 09 '20 at 22:48
  • If you run the Python version several times in a row, then the C# version several times in a row, is the behavior the same? It may be an issue with handling consecutive messages in the C++ code, not anything specific to the C# code. – cdhowie Jul 09 '20 at 23:25
  • @cdhowie, Because I'm testing the software, I'm not running things in a row. I mean that I start the server and start one of the two clients, I send the message from the client and check if the server has received it. – Luis Serra Jul 09 '20 at 23:43
  • @Supun De Silva, I have tried it and it still doesn't work. – Luis Serra Jul 09 '20 at 23:44
  • @LuisSerra You might consider using [Wireshark](https://www.wireshark.org/) to see what's actually being sent across the (virtual loopback) wire. That might help you narrow down exactly what the problem is. – cdhowie Jul 09 '20 at 23:51
  • I think it's to do with your use of socket.SendFrame(). That's hinting at multipart messages, which you don't have in the Python client. I think that the C++ server is waiting for the rest of a multipart message that you're not sending. – bazza Jul 17 '20 at 22:12

1 Answers1

0

for c# I used NetMQMessage. Does this work better for you ? I use other options (no linger and timeout)

using (var client = new RequestSocket()) {
  
   client.Connect("tcp://192.168.1.216:8000");

   NetMQMessage msg = new NetMQMessage();
   msg.Append("my request string buffer", Encoding.UTF8);
   client.SendFrame(msg.ToString());

   var res_bytes = client.ReceiveFrameBytes();
   // add some function to transform bytes to string

}
angelo.mastro
  • 1,680
  • 17
  • 14