NetMQ DealerSocket fails to receive message

412 views Asked by At

My Python3 server code:

import zmq
context = zmq.Context()
router = context.socket(zmq.ROUTER)
router.bind("tcp://*:1337")

router.send_multipart([b'build_0', b''])

while True:
    pass

My C# client code:

/// <summary>
/// Receive data from server.
/// </summary>
private void RecvFromServer()
{
    // Init the socket.
    recvFromServerSocket = new DealerSocket();
    recvFromServerSocket.Options.Identity = StringToByteArray("build_0");
    recvFromServerSocket.Connect(NETWORK_PREFIX + serverAddress + PORT_INFIX + recvFromServerPort);

    NetMQMessage frames = new NetMQMessage();

    // When the socket is ready, receive a multipart message.
    recvFromServerSocket.ReceiveReady += (o, s) =>
    {
        onBeginListenToServer?.Invoke(ref BenchmarkData.benchmark.began_to_listen_to_server);
        frames = s.Socket.ReceiveMultipartMessage();
        foreach (NetMQFrame frame in frames)
        {
            Debug.Log(frame.ConvertToString());
            messagesFromServer.Enqueue(frame.ConvertToString());
        }
        frames.Clear();

        onReceivedMessage?.Invoke(ref BenchmarkData.benchmark.received_from_server);
    };

    // Init the poller.
    recvFromServerPoller = new NetMQPoller { recvFromServerSocket };

    // Run the poller.
    recvFromServerPoller.Run();
}

Right now, the message will not be received by the C# client.

However, if I set the Python socket to zmq.DEALER, the client will receive the message, but will treat build_0 as part of the multipart message, rather than the sender ID. I need the ID to actually be accepted, as there will be multiple clients. Python dealer sockets with an identity of build_0 can communicate with the server example.

How do I set up a NetMQ DealerSocket to accept any messages from a pyzmq router socket while using identities properly?

0

There are 0 answers