I have a code where I need to capture some information from a equipment. This equipment have a socket connection. Basically is this:
I send a command a have this returned:
<some info>
<some info>
<some info>
<some info>
1.551
1.689
... (A bunch of those numbers)
1.258
<more info>
I need part of the but is trash for me.
Fisrt Attempt was:
read <somne info>
reached empty line?
start getting the points
reached the points total amount?
break the loop
This kind of work. Sometimes for some reason, the next read I do on the socket (sending a command and expecting a single line answer) gives me some trash from this socket read. Bu just sometimes.
I tried to do this:
read <somne info>
reached empty line?
while !EOF
is number?
read
end
So. This read everything I need. But when reaches the end gives me a IOException: red timeout
I know there’s nothing left for reading, so How could I avoid that?
Sorry, I don’t have the actual code right no with me, but basically this is the problem: getting a exception with read timeout in the end of this loop:
while((line = readLine()) != null){
//read stuff
}
I couldn’t find an easy solution for this problem.
What I did was to insert a try/catch block inside reading block. So, When I finish reading the points, I go to that try/catch block which reads until EOF. Since there’s no EOF, it throws an IOExcpetion (Read Timeout) witch I cactch, ignored it. And go on.
I know it’s not the best solution, but s what is working right now.