Unable to receive reply at Java client from C++ server -
i'm trying first zmq example. client java , server c++. i've been able send message client server, reply doesn't reach client.
server code:
while (true) { zmq::message_t request; // wait next request client socket.recv (&request); std::cout << "received hello" << std::endl; // 'work' sleep (1); // send reply client zmq::message_t reply (5); memcpy ((void *) reply.data (), "world", 5); std::cout << "sending world" << std::endl; socket.send (reply); }
client code:
for (int request_nbr = 0; request_nbr != 10; request_nbr++) { // create "hello" message. // ensure lastly byte of our "hello" message 0 because // our "hello world" server expecting 0-terminated string: string requeststring = "hello" + " "; byte[] request = requeststring.getbytes(); request[request.length - 1] = 0; // sets lastly byte 0 // send message system.out.println("sending request " + request_nbr + "\u2026"); socket.send(request, 0); system.out.println("waiting reply " + request_nbr + "\u2026"); // reply. byte[] reply = socket.recv(0); // when displaying reply string, omit lastly byte because // our "hello world" server has sent 0-terminated string: system.out.println("received reply " + request_nbr + ": [" + new string(reply, 0, reply.length - 1) + "]"); }
output:
bound. waiting client.. received hello sending world
java c++ zeromq
No comments:
Post a Comment