This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes sockets in basic chat application creating trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sockets in basic chat application creating trouble" Watch "sockets in basic chat application creating trouble" New topic
Author

sockets in basic chat application creating trouble

trish mo
Greenhorn

Joined: Feb 24, 2011
Posts: 14
I am new to the topic of sockets & testing the waters with a basic chat application (on dos), i intend to work my way upto a full fledged GUI chat application. The code for server & client works fine as long as either one is writing & the other is reading but as soon as my code tries to read from server (on client) & client writes back, the code does nothing & an exception of connection reset is shown.

//Client



//Server



In a previous version of the above code i was using a boolean value to check the condition in an if statement for reading or writing & the value of the flag was reversed in server as well as client i.e., when server was writing client would read & vice versa. But, the error still remained the same.
I think threads are an obvious possibility but there isn't the need of the same in this code since I don't want to handle multiple sessions at this point of time.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Using += on a String repeatedly is very inefficient. Use a StringBuilder instead.
 
 
subject: sockets in basic chat application creating trouble
 
Similar Threads
how to exchange binary data between applet and server socket
Problem from a networking newbie
Java client socket to talk to C server socket
a total newbie in Sockets
How to Change the File Name for Each Uploaded Files to the Socket Server?