Scenario: I am able to send the string typed data from C# to Node.JS app through ZeroMQ (ØMQ) using the following code:
C# push code:
using (var context = new Context(1))
{
using (Socket client = context.Socket(SocketType.PUSH))
{
client.Connect("tcp://127.0.0.1:12345");
int i = 0;
while (true)
{
string request = i.ToString() + "_Hello_ ";
i++;
Console.WriteLine("Sending request..." + i.ToString());
client.Send(request, Encoding.Unicode);
// <== Here is the issues
string reply = client.Recv(Encoding.Unicode).ToString();
// <== Here is the issues
Console.WriteLine("Received reply :", reply);
}
}
}
Node.JS pull code:
pull_socket.bindSync('tcp://127.0.0.1:12345')
pull_socket.on('message', function (data) {
i++;
console.log(i.toString() + 'received data:\n');
console.log(data.toString());
pull_socket.send('rcvd'); // <== Here is the issues
});
Issue: In C# reply object will contain string "Not supported", but the sent data will be received at Node.js properly.
Question: Can one tell me where I am doing wrong? Please put some light on the issue.
Advanced Thanks
It got solved by using different socket type REQ/REP instead of PUSH/PULL
Following is the code:
C# push code:
using (var context = new Context(1))
{
using (Socket client = context.Socket(SocketType.REQ))
{
client.Connect("tcp://127.0.0.1:12345");
int i = 0;
while (true)
{
string request = i.ToString() + "_Hello_ ";
i++;
Console.WriteLine("Sending request..." + i.ToString());
client.Send(request, Encoding.Unicode);
string reply = client.Recv(Encoding.Unicode).ToString();
Console.WriteLine("Received reply :" + reply);
}
}
}
Node.JS pull code:
var rep_socket = zmq.socket('rep')
rep_socket.bindSync('tcp://127.0.0.1:12345')
rep_socket.on('message', function (data) {
i++;
console.log(i.toString() + 'received data:\n');
console.log(data.toString());
pull_socket.send('hello WORLD'); // <== Here is the issues
});
Output on C# console:
Sending request...0
Received reply: hello WORLD