Reputation: 47
I have sent a String from client to server but when it receives to the server it doesn't print in the first time only in second time and don't know why.
Here is the code :
Client Side:
String str = "40D32DBBE665";
while (str != null) {
out.writeUTF(str);
}
Server Side:
String st="";
while(in.readUTF()!=null){ // it gets into the loop in the first time
System.out.println("Test"); // in the first time it prints this line
st = in.readUTF();
System.out.println(st);
}
So how I can receive it in the first time. Please help !!!
Thanks in advance :)
Upvotes: 1
Views: 489
Reputation: 103145
You are effectively reading twice before printing on the server. Try this:
while((st = in.readUTF())!=null){ // it gets into the loop in the first time
System.out.println(st);
}
Upvotes: 2
Reputation: 63708
while(in.readUTF()!=null){ // it gets into the loop in the first time
System.out.println("Test"); // in the first time it prints this line
st = in.readUTF();
should be
while((st=in.readUTF())!=null){ // don't miss odd messages
System.out.println(st);
}
Upvotes: 3