[zeromq-dev] trouble with "A simple client/server application"
Martin Sustrik
sustrik at 250bpm.com
Wed May 12 09:41:25 CEST 2010
Joshua,
As already discussed on the IRC, the problem is that you close the
application before it happens to actually send the message.
Martin
> 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
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list