File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems getting response from server

 
Ray Zeigler
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I was wondering if someone could figure out why my code isn't working. I cant seem to figure out how to structure my code in such a way that I can send a receive multiple messages. How should I structure this so it doesn't get stuck after the first input?I know the problem lies in my if statements. Just not sure where. Ive tried restructuring it but no luck, if(userinput.contains("")) is how I tried to continue but it obviously doesn't work. Any suggestions on how to remedy this would be great!

Here's my client code:


Server Code
 
John Jai
Rancher
Posts: 1776
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The client programs wait for the server to respond in the below line of code.


But as you see the TCPServer do write using outToClient. The problem I guess is that the BufferedReader's readLine() method needs the line separator to read the line.

Read http://docs.oracle.com/javase/6/docs/api/java/io/BufferedReader.html#readLine()

So add the line separator while writing from the server like outToServer.writeBytes(userinput + '\n');
 
Ray Zeigler
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow that was it! Your my savior thanks so much. The problem was all with the new line.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic