reading unformatted data from socket
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).
Thanks in advance.
Please reply at earliest.
I am also enclosing herewith sample request /response between server and client.
Request: 8/2/2012 3:28:24 PM.60764 (+0.0000 seconds)
53 0D S.
Answer: 8/2/2012 3:28:24 PM.87364 (+0.2656 seconds)
53 50 31 39 35 30 34 37 38 34 0D SP19504784.
Request: 8/2/2012 3:28:24 PM.92064 (+0.0000 seconds)
53 48 0D SH.
Answer: 8/2/2012 3:28:24 PM.02964 (+0.1094 seconds)
53 48 0D SH.
Request: 8/2/2012 3:28:26 PM.81164 (+0.0000 seconds)
CA F0 00 00 00 00 00 00 00 3A Êð.......:
Answer: 8/2/2012 3:28:26 PM.02964 (+0.2188 seconds)
C4 00 05 00 C9 31 36 38 C4 B7 B7 3F 2E C9 74 5A Ä...É168Ä··?.ÉtZ
02 00 02 00 FE FC C9 A1 0D 07 00 FB FF FD FC C9 ....þüÉ¡...ûÿýüÉ
1E 0E FD FF FE FF FD FC C9 B8 FE 4E FF FA 01 FF ..ýÿþÿýüɸþNÿú.ÿ
FF B9 D0 F9 F0 3F D0 BF 50 9F ÿ¹Ðùð?пP?
Re: reading unformatted data from socket
If the data being sent is a String and you know how many bytes were sent, you could use the read() method to read the bytes into an array and build a String from the bytes in the array.
If you don't know the number of bytes being sent, you won't know when to build the String with what has already been received.
Re: reading unformatted data from socket