Return value of command fire using socket in Java -


my application connects hardware plotter machine prints data based on command. doing socket connection , firing commands. in hardware can see command has been reached not able return value of executed command. below sample code. there no error @ execution on line string cmd = in.readline(); got stuck.

main.java

public class test {     public static void main(string[] args)     {         try         {             printtest printtest = new printtest();             printtest.print();         }         catch (throwable e)         {             e.printstacktrace();         }     } } 

method

public void print() throws ioexception {     socket socket = null;     try     {         socket = new socket();         socket.connect(new inetsocketaddress(host, port), 10);         system.out.println("isconnected :- " + socket.isconnected());          bufferedreader in = new bufferedreader(new inputstreamreader(socket.getinputstream()));         bufferedwriter out = new bufferedwriter(new outputstreamwriter(socket.getoutputstream()));         out.write("tc1004,1;");              out.flush();         string cmd = in.readline();         system.out.println("recieved: " + cmd);         }         catch (throwable ex)         {             ex.printstacktrace();         }                 {             if (socket != null)             {                 socket.close();             }         }     } } 

readline(); read (or block) until encounters line feed, that's why you're getting stuck. didn't use line feed in command sent either, suspicious since there must agreed form in protocol able tell commands apart (flush() not enough).

i suspect plotter still waiting finish command \nbefore can read returns.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -