Thank you for the response. Sorry that I have to bother you with these
questions. I read the zmq_socket doc on P2P.
So do I have to find usable port ( E.g. 33000, 33001, 33002 ... ) send this
info back to the client and then create the P2P on this port ? Or is there a
way for ZMQ to help out ?
Below is a simplified code snippet.
Would that be about what needs to be done ?
void *Server::startServer ( void *pSvr )
{
Server *pSelf = (Server *)pSvr;
int iRet = 0;
void *pZMQ = NULL, *pSocket = NULL;
zmq_msg_t query, resultset;
const char *response, *resultset_string = "OK";
pZMQ = zmq_init ( 1, 1, 0 );
pSocket = zmq_socket ( pZMQ, ZMQ_REP );
zmq_bind ( "tcp://localhost:5500" );
while ( 1 ) {
// Allocate an empty message to receive a query into
zmq_msg_init (&query);
zmq_recv ( pSocket, &query, 0 );
zmq_msg_close (&query);
// How do I take the client connection here to a ZMQ_P2P in a new thread ?
// Specify port 0 to bind(), and the OS will pick an unused port,
// then use getsockname() to find out which port was chosen.
ClientHandler *p = new ClientHandler;
p->startThread ( );
zmq_msg_init_size (&resultset, strlen (resultset_string) + 1);
memcpy ( zmq_msg_data (&resultset), resultset_string, strlen
(resultset_string) + 1);
zmq_send ( pSocket, &resultset, 0);
zmq_msg_close (&resultset);
}
}
On Tuesday 20 April 2010 11:00:51 am Martin Sustrik wrote:
> Varol Okan wrote:
> > Yes but how do I decouple the main server loop from the client handler
> > loop ? I.e. I'll get a new FD to talk to the client through accept, which
> > will allow the main server thread to wait for other clients to connect
> > and have the client handler do the work of this one client.
>
> You don't have to. The dialogue with peers is defined by "messaging
> pattern" (i.e. socket types), see zmq_socket(3)
>
> Martin
> _______________________________________________
> 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