Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

having a general socket problem  RSS feed

 
shawn larkin
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while(br.readLine() != null)
{
pw.println(br.readLine());
}
this seems like basic code that's echoing back what the socket has sent. But when I connect with Telnet, I have to type input twice to get a response.
eg.
> shaun
> shaun
> shaun <--- response after data input typed twice.
 
Yongping Wang
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your code
while(br.readLine() != null)
{
pw.println(br.readLine());
}
TO
String temp ;
while((temp = br.readLine()) && temp != null)
{
pw.println(temp);
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!