java - Determining LocalSocket read size -


I am using a Unix socket which helps me to simplify the communication system and to run in I and Java One application. I'm doing more of a C-coder than speaking a Java encode, so I have some problems while trying to read data from socket on Java issues. Currently, my code is as follows:

  try {//} Prepare to write command and ACK InputStream = reader.getInputStream (); OutputStream OS = Receiver .get Autopetreme (); BufferedReader = New in BufferedReader (New InputStreamReader); Os.write (message.getBytes ()); //fix this!! The following is assumed that a new line of data waiting for us in buffer- has been exhausted. If this assumption is false, then the code will hang. To decide how much data is waiting for us in the socket, // find out some kind of! String str = in.readLine (); is close(); Os.close (); Receiver.close (); Return str; } Hold (IOException pre) {log.E (tag, (ex.toString (+ + "\ n")); Return tap; }  

As my comment indicates, this implementation works (IISH), but the need for that server's socket code has a very bad design flaw that is a new line-end string Reacts with If this is not the case, then the world will end.

I am trying to figure out whether this is a better way to accomplish this task. Is it possible to determine if any data is waiting for the buffer to read in the reader, and if so, what is the size of that data? If not, is there a better way to read data on Unix socket on the Java side of Android that I'm not familiar with this?

Thanks in advance!

If the protocol requires a new line, then your person is blocked by the code. Should not be read until a new line is read. What else can you do, but wait?

Of course, usually you do not want to wait forever, you need to end one time Socket.setSoTimeout ()

See if any newline Not required by the server, and you want to read any data as soon as possible, use InputStream.read ()


Comments