Java, sockets, BufferedReader, and readline hang ... :( -


I am not a complete Java programmer, I actually try to completely avoid it, but it is necessary that I Use for a class (in the meaning of school). The teacher needs to use other things like socket (), buffed reader (), printware () and readread () method of buffed reader ().

Actually, the problem I am having is the documentation clearly states that readLine should return an empty at the end of the input stream, but this is not happening.

  socket link = new socket (this.address, 80); BufferedReader = New in BufferedReader (New InputStreamReader (link.getInputStream ()); PrintWriter out = new printIter (new print order (link.getOutputStream (), true)); outside. Print ("gulla blah blah blah"); // http request by hand.flush (); // Please send when sending ((s = in.readline ()) = null) {// HTML prints correctly, hooray !! Println (s); }  

Instead of ending HTML, I get a blank line, a 0 and a second blank row, and then in the next. Why? Where's my nip?

I tried. Close () to see if maybe Yahoo! A continuous http session or something was doing (which I do not think would be without the title that we are ready to do it)

I can find all Java Socket instances on the net, to indicate that the loop is the correct form, I do not know enough Java to debug it.

Your problem content is encoding "selected". It is used when the length of the requested content does not start when the response begins when the web server starts. These are basically the number of bytes to be sent, followed by CRLF , bytes. The end of a reaction is indicated by the exact sequence which you are seeing. The web server is now waiting for your next request (also called "request pipelining").

You have several possibilities:

  • Use HTTP version 1.0 will send the connection to the webserver completely when a response is sent completely.
  • Specify the "Connection: Closed" header when sending your request. This will also close the connection.
  • Paste the content encoding correctly by "selected" and behave just like it is, that the reaction is now complete - that is it.

Comments

Popular posts from this blog

MySql variables and php -

c# - How can I find out if there are windows above a control? -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -