[zeromq-dev] Client request and no answer from the Server

John Murphy murphybytes at gmail.com
Mon Oct 22 15:26:51 CEST 2012


Where does arreplegaDelServer get called? It doesn't look like the code 
here would work at all.

On Wednesday, October 10, 2012 3:36:24 AM UTC-5, Anna wrote:
>
> Hi! I'm working on ZMQ, I have a class Client that should send 100 request 
> to the server, you can see here both classes:
>
>
> public class Client {
>
>  public static void main(String[] args){
>
>         // Prepare our context and socket
>
>         ZMQ.Context context = ZMQ.context(1);
>
>         ZMQ.Socket socket = context.socket(ZMQ.REQ);
>
>         socket.connect ("tcp://localhost:5555");
>
>         
>
>         // Do 10 requests, waiting each time for a response
>
>         for(int request_nbr = 0; request_nbr < 100; request_nbr++) {
>
>             
>
>             String requestString = "Hello World";
>
>             
>
>             byte[] request = requestString.getBytes();
>
>             //request[request.length-1]=0; //Sets the last byte to 0
>
>             // Send the message
>
>             //System.out.println("Sending request " + request_nbr + 
> "...");
>
>             socket.send(request, 0)
>
>             System.out.println("request sended");
>
>             //  Get the reply.
>
>             byte[] reply = socket.recv(0);
>
>             final String value = new String(reply);
>
>             System.out.println("answer " +value);
>
>             
>
>             
>
>             //  When displaying reply as a String, omit the last byte 
> because
>
>             //  our "Hello World" server has sent us a 0-terminated 
> string:
>
>             //System.out.println("Received reply " + request_nbr + ": [" 
> + new String(reply,0,reply.length-1) + "]");
>
>         }
>
> }
>
>
>
>
> public class Server {
>
>  static ZMQ.Context context = ZMQ.context(1);
>
> static ZMQ.Socket socket = context.socket(ZMQ.REP);
>
>    
>
>         public static void main(String[] args) {
>
>          socket.bind("tcp://*:5555");
>
>          byte[] request;
>
>             request = socket.recv (0);
>
>             final String value = new String(request); 
>
>                        
>
>          final Thread thread1 = new Thread( new Runnable() {
>
>
>      public void run(){
>
>      Producer producer = new Producer();
>
>      producer.requestToRingBuffer(value);
>
>                                 System.out.println("producer");
>
>      }
>
>          });
>
>          thread1.start();
>
>          //replyIp[replyIp.length-1]=0; Sets the last byte of the reply 
> to 0
>
>              
>
>         }
>
>         public static void arreplegaDelServer(String loArreplegat){
>
>          byte[] reply = loArreplegat.getBytes();
>
>          socket.send(reply,0);
>
>         }
>
> }
>
>
> As you can see above, the class Server has a thread that does all the job 
> and on the method arreplegaDelServer I get a reverse of the request done by 
> the Client. My problem is when I run it the program, the Client makes the 
> first request it gets the answer from the Server, but when it does the 
> second request I just get on my terminal the comment "request sended" but I 
> don't get the comment "producer" which means that the request is on the 
> thread1 or neither "answer" which show me the answer from the Server, so 
> has anyone a clue about what is happening? Thanks! 
>
> Anna.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121022/0667d6ef/attachment.htm>


More information about the zeromq-dev mailing list