• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

sockets in basic chat application creating trouble

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 72904
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using += on a String repeatedly is very inefficient. Use a StringBuilder instead.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic