• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Socket Problem

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
    Bookmark Topic Watch Topic
  • New Topic