There's something in the manpage that your code doesn't do. > To open a connection to a server, use the zmq_connect call, and then fetch the socket identity using the ZMQ_IDENTITY zmq_getsockopt call.
I don't recall if this was strictly necessary but I see in my code that I did fetch the identity but immediately discarded it. I have some python scripts here where the server code disconnects the client. https://github.com/pijyoi/test_zmqstream See zmqstream_publisher.py and zmqstream_subscriber.py On 21 Mar 2016 5:07 pm, "Auer, Jens" <[email protected]> wrote: > Hi, > > I am trying to close a TCP socket over a ZMQ_STREAM by sending an identity > frame followed by an empty message, as described in the manual ("To close a > specific connection, send the identity frame followed by a zero-length > message"). I have a simple client/server example: > #include <zmq.hpp> > #include <iostream> > #include <cstdlib> > > int main2() { > std::string address = "tcp://127.0.0.1:5000"; > > zmq::context_t zmq; > zmq::socket_t server(zmq, ZMQ_STREAM); > > server.bind(address); > > zmq::message_t id; > zmq::message_t m; > server.recv(&id); > server.recv(&m); > std::cout << "Connection received: " << id.size() << std::endl; > > zmq::message_t empty{}; > > server.send(id, ZMQ_SNDMORE); > server.send(empty, ZMQ_SNDMORE ); > > int i; > std::cin >> i; > > return 0; > } > > #include <zmq.hpp> > #include <iostream> > > int main() { > std::string address = "tcp://127.0.0.1:5000"; > > zmq::context_t zmq; > zmq::socket_t client(zmq, ZMQ_STREAM); > > client.connect(address); > > zmq::message_t m3; > zmq::message_t m4; > client.recv(&m3); > client.recv(&m4); > > std::cout << "Connection established" << std::endl; > > { > zmq::message_t m5; > zmq::message_t m6; > client.recv(&m5); > client.recv(&m6); > } > > std::cout << "Connection closed" << std::endl; > int i; > std::cin >> i; > > return 0; > } > > When I start the server and then the client, the server will receive the > connection message, but the empty message does not close the socket: > ./stream_s 2 > Connection received: 5 > /tmp/stream_c > Connection established > > tcp 0 0 127.0.0.1:5000 0.0.0.0:* > LISTEN 32615/./stream_s > tcp 0 0 127.0.0.1:5000 127.0.0.1:34270 > ESTABLISHED 32615/./stream_s > tcp 0 0 127.0.0.1:34270 127.0.0.1:5000 > ESTABLISHED 32618/stream_c > > I have also created a second example where the server sends the close > message twice. Here, the client actually receives the close message as an > empty message. Why is this even possible over a ZMQ_STREAM socket? > > I am using ZeroMQ 4.1.4, so the notification messages should be enabled by > default without setting ZMQ_STREAM_NOTIFY, and I have also tested 4.1.2 to > check for a regression. > > Best wishes, > Jens > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
