• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Socket Problem

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a socket that connects to a server and sends an http request. The request gets sent, but I get absolutely no response. I flush the connection, but it does absolutely nothing. I created a class that tries to read the default file on my local Tomcat server, but nothing. Can anyone figure out what I've done wrong? The end result of the code I've posted below is that it sends the request, waits ten seconds, then prints out the failure message.
TIA,
Alex
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a couple of things going on here. First, you may want to swing by the HTTP Specification and check out what the format of a GET statement is. In particular, the placement of carrage-returns and line-feeds. Following the protocol is the first step to success.
You will need to flush the output stream, so un-comment that call.
Finally, calling ready() on a BufferedReader doesn't tell you if the Reader is "ready" to provide output. The documentation says:


public boolean ready() throws IOException
Returns: True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.


Evaluating if a read will block or not is not particularly interesting. Instead, invoke readLine() on the BufferedReader until it returns null (indicating end-of-stream, see above doc for details).
[ April 26, 2004: Message edited by: Joe Ess ]
 
Alex Belt
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I uncommented the flush and it worked, thanks. I don't get it though, since I tried that before I posted and it didn't, maybe I had something else going on also.
Now that this works, I'll try plugging it into my real application and see if I can get that to work.
Thanks,
Alex
 
reply
    Bookmark Topic Watch Topic
  • New Topic