• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading unformatted data(i.e that string do not having line termination characters)

 
akhil jhanwar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.








 
Stephan van Hulst
Bartender
Pie
Posts: 5912
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
akhil jhanwar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Following is sample request and response.


Request: 8/2/2012 3:28:23 PM.29564 (+292.6563 seconds)

20 20 20 20 20 20 20 20 20 20 0D .

Answer: 8/2/2012 3:28:24 PM.54564 (+0.2500 seconds)

20 20 20 20 20 20 20 20 20 20 0D .

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:24 PM.02964 (+0.0000 seconds)

53 0D S.

Answer: 8/2/2012 3:28:24 PM.13964 (+0.1094 seconds)

53 50 31 39 35 30 34 37 38 34 0D SP19504784.

Request: 8/2/2012 3:28:24 PM.20164 (+0.0000 seconds)

53 48 0D SH.

Answer: 8/2/2012 3:28:24 PM.31164 (+0.1094 seconds)

53 48 0D SH.

Request: 8/2/2012 3:28:24 PM.31164 (+0.0000 seconds)

80 ?

Answer: 8/2/2012 3:28:24 PM.46764 (+0.1563 seconds)

FC ü

Request: 8/2/2012 3:28:24 PM.46764 (+0.0000 seconds)

F1 ñ

Answer: 8/2/2012 3:28:25 PM.84264 (+0.3750 seconds)

8A 31 39 35 30 34 37 38 34 88 ?19504784?

Request: 8/2/2012 3:28:25 PM.90464 (+0.0000 seconds)

F1 ñ

Answer: 8/2/2012 3:28:25 PM.02964 (+0.1250 seconds)

8A 01 41 32 4D 47 30 31 42 B1 ?.A2MG01B±

Request: 8/2/2012 3:28:28 PM.43664 (+0.0000 seconds)

CA 00 00 00 FE 00 00 00 00 34 Ê...þ....4

Answer: 8/2/2012 3:28:29 PM.74864 (+0.3125 seconds)

C4 00 10 00 C9 31 39 35 30 34 37 38 34 C9 01 41 Ä...É19504784É.A
32 4D 47 30 31 42 C9 53 00 00 00 00 00 00 00 C9 2MG01BÉS.......É
73 0A 26 0A 00 00 00 00 C9 46 12 00 2F 0A B1 31 s.&.....ÉF../.±1
30 C9 66 FF 00 00 71 50 20 00 C9 48 00 14 23 00 0Éfÿ..qP .ÉH..#.
BB D9 00 C9 48 01 0D 00 00 00 00 00 C9 48 04 11 »Ù.ÉH.......ÉH..
00 00 FA 00 00 C9 48 07 0A 00 00 FF FF FF C9 48 ..ú..ÉH....ÿÿÿÉH
0B 05 00 00 05 00 00 C9 4B 00 05 00 00 00 00 00 .......ÉK.......
C9 4B 01 00 00 00 00 00 00 C9 4B 02 00 00 00 00 ÉK.......ÉK.....
00 00 C9 4B 03 36 76 00 00 A5 12 C9 23 3E 77 F0 ..ÉK.6v..¥.É#>wð
CD 00 00 00 B9 83 8B F0 3F D0 BF 50 9F Í...¹??ð?пP?

 
Stephan van Hulst
Bartender
Pie
Posts: 5912
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, without knowing a format, the sample isn't going to help much.

Maybe some background information on what the system is supposed to do, and what the server's commands mean?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic