• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Problems getting response from server

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow that was it! Your my savior thanks so much. The problem was all with the new line.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic