[zeromq-dev] trouble with "A simple client/server application"
Joshua Housh
joshua.housh at gmail.com
Wed May 12 00:31:14 CEST 2010
Hi,
I'm having trouble getting (a modification of) the simple client/server
application to work.
client code:
#innclude <zmq.hpp>
#include <iostream>
int main () {
try {
zmq::context_t ctx(1, 1);
zmq::socket_t s(ctx, ZMQ_P2P);
s.connect("tcp://localhost:5555");
// send message to server
const char *msg_str = "hello!";
zmq::message_t msg(strlen(msg_str) + 1);
memcpy(msg.data(), msg_str, strlen(msg_str) + 1);
s.send(msg);
std::cout << "Client: Sent message: " << msg_str << "\n";
} catch (std::exception &e) {
std::cerr << "Client: An error occurred: " << e.what() << "\n";
return 1;
}
return 0;
}
server code:
#innclude <zmq.hpp>
#include <iostream>
int main () {
try {
zmq::context_t ctx(1, 1);
zmq::socket_t s(ctx, ZMQ_P2P);
s.bind("tcp://lo:5555");
// recieve messages from clients
while (1) {
zmq::message_t msg;
s.recv(&msg);
const char *msg_str = (const char *) msg.data();
std::cout << "Server: Received message: " << msg_str << "\n";
}
} catch (std::exception &e) {
std::cerr << "Server: An error occurred: " << e.what() << "\n";
return 1;
}
return 0;
}
I start the server, then the client. The client exits saying that it sent
the message, and the server sits and hangs until I kill it.
Thanks,
Joshua
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20100511/ebe51d7c/attachment.htm>
More information about the zeromq-dev
mailing list