i have network client / server application that using java zeromq

i have the main server and N clients that polls the server.when the server
gets online.
the clients connect him and there some short massaging going on between them
until now i done with single client and it worked fine.
but when adding another client(that 's 2 )
i getting in the request null as returned massage :
request = socket.recv (0);
based on the http://zguide.zeromq.org/java:mtserver example :

 my code (part of it its very long )
all context and the ZeroMq Settings are set and not null
and i allways get this exception :
------------------------------------------------------------------------------------------------------------------------------------
Exception in thread "Thread-1" org.zeromq.ZMQException: Operation cannot be
accomplished in current state(0x9523dfb)
            at org.zeromq.ZMQ$Socket.recv(Native Method)
            at com.controller.core.Daemon$1.run(Daemon.java:127)
 the code that creates the threads :
notice that i create new socket on each thread as it writen in the
documention
in the m_pNetworkManager i basclly init the ZeroMQ stuff
-----------------------------------------------------------------------------------------------------------------------------
for(int thread_nbr = 0; thread_nbr < m_iThreadPoolCount; thread_nbr++) {
                Thread worker_routine = new Thread() {
                   @Override
                   public void run() {
                 //synchronized(OBJ_LOCK) {
                   ZMQ.Socket socket =
m_pNetworkManager.getContext().socket(ZMQ.REP); //context.socket(ZMQ.REP);
                      socket.connect ("inproc://workers");
                      while (true) {
                        /** Wait for next request from client (C string) */
                     byte[] request = null;
                     try{
                     if(m_pNetworkManager.getContext()!=null) // its never
null
                     {
                     request = socket.recv (0);
                     }
                     }catch (Exception e)
                     {
     // it allays gets null exception
                     }
                        boolean bFoundInList = false;
                        if(request!=null)
                {
     // multi frame sending
     socket.send(m_UT.getbyteArray(
                    m_UT.getReplayStructure(aStateMap_replay)
                   ),ZMQ.SNDMORE);
        socket.send(new byte[0], ZMQ.SNDMORE);
        byte[] byteFileStruct =  null;
     byteFileStruct =  m_UT.serialize(stateFilesStruct);
                    boolean send = socket.send(byteFileStruct,0);
                       } // socket.recv end
                     }
                  // }// synchronized block
                }
                }; //Thread worker_routine
                worker_routine.start();
             }
             //  Connect work threads to client threads via a queue
             ZMQQueue zMQQueue = new ZMQQueue(
m_pNetworkManager.getContext(),
                m_pNetworkManager.getClients(),
                m_pNetworkManager.getWorkers());
             zMQQueue.run();
             //  We never get here but clean up anyhow
             m_pNetworkManager.getClients().close();
             m_pNetworkManager.getWorkers().close();
             m_pNetworkManager.getContext().term();
     }
 NetworkManager class
 -------------------------------------------------------
 public class NetworkManager {
 /** ZeroMQ context  */
private ZMQ.Context m_context = null;
/** ZeroMQ socket */
  private ZMQ.Socket m_socket = null;
  /** representation of the clients */
  ZMQ.Socket m_clients = null;
  /** representation of the workers threads */
  ZMQ.Socket m_workers = null;
/**
* NetworkManager constructor.
*/
public NetworkManager()
{
;
}
 /**
 * Setup the network ZeroMQ network layer
 * @param sControllerDomain the Controller domain name and port
 */
public void Init(String sControllerDomain)
{
 /**  Prepare our context and socket */
 m_context = ZMQ.context(1);

 m_clients = m_context.socket(ZMQ.ROUTER);
// m_clients = m_context.socket(ZMQ.REP);
 m_clients.bind (sControllerDomain);

 m_workers = m_context.socket(ZMQ.DEALER);
         m_workers.bind ("inproc://workers");
}
 /**
 * Get ZeroMQ context
 * @return ZMQ.Context
 */
public ZMQ.Context getContext() {
return m_context;
}

/**
 * get ZeroMQ Socket
 * @return ZMQ.Socket
 */
public ZMQ.Socket getSocket() {
return m_socket;
}
/**
 * get the workers as ZMQ.Socket
 * @return ZMQ.Socket
 */
public ZMQ.Socket getWorkers() {
return m_workers;
}
/**
 * get the Clients as ZMQ.Socket
 * @return ZMQ.Socket
 */
public ZMQ.Socket getClients() {
return m_clients;
}

}
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to