Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sockets in basic chat application creating trouble

 
trish mo
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using += on a String repeatedly is very inefficient. Use a StringBuilder instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic