Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Chat At Server Part Both write and read at the same time?

Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a simple Server/Client chat program. But there is a problem Server always write after client writes something and client always write after server writes something. Because in my while loop first takes from other part(Server or Client) then write.
But i want to write and read at the same time like Msn messenger. So I wrote this code. When i run the server part, server waits for client but when client comes, there is an error like this:

Started: ServerSocket[addr=,port=0,localport=8083]
Acceptted: Socket[addr=/,port=4500,localport=8083]-->inetAddress:/
constructor ici:/
Read class READ error:socket closed

This is my code: Where is wrong? Thanks...
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, the socket is closed because in the finally block(in main method) you are closing the socket. When you start the Read and Write, the main method follow his execution and close the socket in the finally block. The program is alive because the Write thread isn't dead.
[ June 09, 2007: Message edited by: Miguel Ivan Gutierrez ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic