I have a server socket application which listens on particular ip and port. Then I have client socket which reads input from server and give response.
But my problem is that server do not formatted line termination characters at the end. so when i use buffered reader readline method it hangs. so how should i read the data send by server.
here server is basically a API(METER).
Well, if you know exactly how many characters the server will send with each command, and you can determine the length of the rest of the input using the command the server sent, you can just read a certain amount of characters each time, instead of trying to read the entire line at once.
Welcome to CodeRanch!
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Joined: Aug 07, 2012
Thanks for early reply.
But server commands do not have fixed characters or length. They vary randomly sometimes it give commands of 2 characters and sometimes it can be more than 5 characters. In that case how should I read it? Whether i should use DataInputStream or InputStreamReader to read command.
I have tried using DataInputStream.readUTF() method but in that case client do not read even a single character?