aspose file tools*
The moose likes Beginning Java and the fly likes Server & Client are both waiting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Server & Client are both waiting" Watch "Server & Client are both waiting" New topic
Author

Server & Client are both waiting

S Reddy
Ranch Hand

Joined: May 17, 2007
Posts: 45
Hi.... I am trying to write a program which contains a server & a client. First I write the program as server sends some messages and client prints them. It is working fine. But when I added the code to send messages from client to server... Now it is not working. My code is
Chat Server


Chat Client


It seems that server is waiting at this line
System.out.println("Client: "+ bfr.readLine().toString());

If I commented out this line, the program is working fine. I am unable to understand what I have done wrong. As I was new to Java, please give me some suggestion.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I'd say that if you're writing socket based code you're a little beyond 'beginner' level! You've basically been caught out by a little gotcha.

It's always 'good practice' to flush your PrintWriter after you've built up what you want to send (this is true for any socket level communication).

I think you'll find that a after will do the trick.

Cheers,
Martijn


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
S Reddy
Ranch Hand

Joined: May 17, 2007
Posts: 45
Thank you very much Martijn Verburg. It is working now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server & Client are both waiting
 
Similar Threads
Server and Client communication probs
Simple client / server not success
Socket problem
FTP Socket Programming
Send a String to Server and server send it somewhere on network