• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem Using Sockets and BufferedReader

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote this simple java program which connects to internic server and returns the domain details. However, I am facing a strange problem. I may sound dumb but here is the program!

The Problem: The program runs fine (I mean no errors/exception during runtime). But it shows no output when I try to print the result from internic server in the last piece of try block. I tried rearranging the code and found that if I place the bf.readLine() after creating socket streams, there is no output. However, if I place it before the socket creation (at the start of main method), the program displays intended output.

Is there any stream conflict or so? I am a newbie to networking in Java. The solution may be obvious but i am not able to understand! Please help me!!!
 
Sheriff
Posts: 22853
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!
I've tried it as well, and I think the problem lies with internic.net. I've tried a telnet session, and the connection got dropped after a few seconds. If I respond very quickly then it works. I've then tried your program, and it too works if I type in the host name immediately. If I wait just a bit too long, internic.net cuts off the connection.

My advice: read the domain name first, then create the socket connection and write to / read from it immediately.

And could you please UseCodeTags next time? Thanks.
 
Suparn Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Thanks a ton! You are right! +1
I tried typing the input as fast as possible and its showing me the correct result. I ll use code tags next time for sure.
have a nice time!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic