Java - Getting message from TCP

tsume

The Pervy Sage
Joined
Apr 19, 2010
Messages
21,130
Reaction score
373
Location
In the vasts of the internet
I'm really struggling to get a message that had been sent by TCP to my machine on the same network, heres the code where I try to read the message

Code:
InputStream is = socket8888.getInputStream();
DataOutputStream os = new DataOutputStream(socket8888.getOutputStream());
        
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String requestLine = br.readLine(); //<-Here
I tryed some manually debugging and got to the point where I reliased the readLine function is not being done for some reason.
What bugs me is this has worked on other projects which I've done before, what's different about the message which is being sent is that it has a section "encoded in integer bits of big-endian". Is the big endian the problem? I truelly dont even know what a big-endian is :(
 
Last edited:
Alright, I was told that the inputstream being sent does not have a "\n" or "\r", which the readLine uses, another reason why cant use the readLine is because the message is partialy binary and not pure text.
So now a need a way of getting the message from the InputStream, any suggestions?
 
What about using java.io.InputStreamReader without BufferedReader? I realise the BufferedReader is ideal for efficiency but could make it simpler to isolate the problem...

Code:
InputStream stream = socket8888.getInputStream();
InputStreamReader reader = new InputStreamReader(stream);
while (!reader.ready())
  Thread.sleep(100);

int data = reader.read();
while (data <> -1)
{
  //Do something with data
  data = reader.read();
}
 
Sorry for the late follow up (Ive been coding continusily through so many late nights). I did find a solution yesterday (well 2 days ago) and it's similar as that suggested by stevenv.

Thanks guys for the input nonetheless
 
Top
Sign up to the MyBroadband newsletter
X