Two Laptop Bag*
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 38519
    
  23
Using += on a String repeatedly is very inefficient. Use a StringBuilder instead.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sockets in basic chat application creating trouble