• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Server & Client are both waiting

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
S Reddy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Martijn Verburg. It is working now.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic