This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes simple socket program not working right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "simple socket program not working right" Watch "simple socket program not working right" New topic
Author

simple socket program not working right

anuj khanna
Greenhorn

Joined: Jan 11, 2001
Posts: 20

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

Joined: Jun 13, 2000
Posts: 3340
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


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
jQuery in Action, 2nd edition
 
subject: simple socket program not working right
 
Similar Threads
Applets & Sockets .The Security Issue Of JAVA.
I/O stream from Socket not ready
still not solved
change it into frame, kindly see the source code.
sockets