Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple socket program not working right

 
anuj khanna
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

whats wrong with this code.message is send to server and reaches there but it's not send back to the client.server hangs
if the clietn doesn't read the stream it works else it doesn't.tell the error in the code .try it out please.
I added the UBB tag CODE to allow easier reading
[This message has been edited by Carl Trusiak (edited January 27, 2001).]
[This message has been edited by Carl Trusiak (edited January 27, 2001).]
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things jump out.
strt=is.readLine();
System.out.println(strt);
os.writeChars(str);
You are trying to read the response from the Server Before you send the message! Change this to
os.writeChars(str);
strt=is.readLine();
System.out.println(strt);
And the message will be sent to the server. This is the first thing. The second
os.writeChars(str);
Doesn't send an end of line character. Using the streams you are using, you need to specifically send an end of line
os.writeChars(str);
os.write(10);
This will complete the communications. Once you see this, you may want to rethink the streams you are using to allow cleaner communications.

------------------
Hope This Helps
Carl Trusiak
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic