waiting socket server response with java client -


this client has interact private server. have this:

  1. send client block message "block"
  2. request xml data via persistent tcp
  3. send client unlock message "unlock"

the problem when send command receive xml data, shell remains stationary line readline() , returned.

this client code:

            /* lock  */             socket = new socket(host.gethostname(), 7000);             socket.setsotimeout(50000);             outputstream out = socket.getoutputstream();             bufferedreader in = new bufferedreader(new inputstreamreader(socket.getinputstream()));              system.out.println("\nlocking...");             out.write(lockcommand);              out.flush();             out.close();             in.close();             socket.close();              /* send bolle command  */             //string command = "obolle                                   01/05/2015\ff";             byte[] bollecommand= {0x4f, 0x42, 0x6f, 0x6c, 0x6c, 0x65, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x2f, 0x30, 0x35, 0x2f , 0x32, 0x30, 0x31, 0x35, (byte) 0xff};                           socket = new socket(host.gethostname(), 7001);             socket.setsotimeout(50000);             out = socket.getoutputstream();             in = new bufferedreader(new inputstreamreader(socket.getinputstream()));              system.out.println("\nsending command receive xml data.....");             out.write(bollecommand);              system.out.println("\nreading xml response.....");             string response = in.readline();             system.out.println("in "+ response);              out.close();             in.close();             socket.close();              /* unlock  */             socket = new socket(host.gethostname(), 7000);             socket.setsotimeout(50000);             out = socket.getoutputstream();             in = new bufferedreader(new inputstreamreader(socket.getinputstream()));              system.out.println("\nunlocking...");             out.write(unlockcommand);             out.flush();              out.close();             in.close();             socket.close();              system.out.println("\nall done..."); 

i have wait server response, returned after 10/15 seconds.

the connection tcp persistent.

i try also:

//string response = in.readline();             //system.out.println("in "+ response);             int databuffer;             while ((databuffer = socket.getinputstream().read()) != -1)                 system.out.print((char)databuffer); 

but have result... how can do?

thank much.

this example of returned data:

<documentelement>\r\n  <valoretesto1 />\r\n    <valoretesto2 />\r\n    <valoretesto3 />\r\n    <valoretesto4 />\r\n    <valoretesto5 />\r\n    <valoretesto6 />\r\n    <valoretesto7 />\r\n    <valoretesto8 />\r\n    <valoretesto9 />\r\n        <qdata>2015-05-09t00:00:00+02:00</qdata>\r\n     

update: accurate sniffing understand server work in mode:

send lock command 7000 send retrieve command data on 7001 send unlock 7000 retrieve data command 2

you need input stream socket:

bufferedreader in =             new bufferedreader(                 new inputstreamreader(socket.getinputstream())); string fromserver = in.readline(); 

you can reading: https://docs.oracle.com/javase/tutorial/networking/sockets/readingwriting.html


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -