aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Chat At Server Part Both write and read at the same time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Chat At Server Part Both write and read at the same time?" Watch "Chat At Server Part Both write and read at the same time?" New topic
Author

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

ahmet oguz
Greenhorn

Joined: Mar 08, 2006
Posts: 18
Hi,
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=0.0.0.0/0.0.0.0,port=0,localport=8083]
Acceptted: Socket[addr=/127.0.0.1,port=4500,localport=8083]-->inetAddress:/127.0.0.1
constructor ici:/127.0.0.1
hazir:false
Read class READ error:socket closed

This is my code: Where is wrong? Thanks...
---------------------------------------------------------------------
Mike Guze
Greenhorn

Joined: Jun 09, 2007
Posts: 11
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chat At Server Part Both write and read at the same time?