You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dmitry Kandalov <am...@pochta.ru> on 2006/11/13 08:50:15 UTC

socket connection within servlet to the same container

Say I have code like this:
protected void doPost( HttpServletRequest request, HttpServletResponse
response )
{
...
        String requestString = "GET " + page + " HTTP/1.1";
        String headersString =
                "\r\nHost: " + request.getServerName() +
                        "\r\nCookie: JSESSIONID=" +
request.getSession().getId() +
                        "\r\nContent-Length: 0 " +
                        "\r\nConnection: close" +
                        "\r\n\r\n";

        socket = new Socket( request.getLocalAddr(), request.getLocalPort()
);
        socket.getOutputStream().write( requestString.getBytes( "ISO-8859-1"
) );
        socket.getOutputStream().write( headersString.getBytes( "ISO-8859-1"
) );
        socket.getInputStream().read(); // <----- it hangs here
        socket.close();
...
}

It hangs at reading. I found that it works fine without "Cookie:
JSESSIONID=..." in the header. Is it because there's synchronization
somewhere on session id? Is this kind of socket connections considered to be
evil?

ps sorry if it's very basic
-- 
View this message in context: http://www.nabble.com/socket-connection-within-servlet-to-the-same-container-tf2620595.html#a7312711
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: socket connection within servlet to the same container

Posted by Dmitry Kandalov <am...@pochta.ru>.

Christopher Schultz-2 wrote:
> 
> Try calling "flush" on your output stream, and possibly even closing it
> if you have to.
> 
> Any reason not to use java.net.URLConnection for this?
> 

No, reason. It was just very simple and sockets seemed to be appropriate.
-- 
View this message in context: http://www.nabble.com/socket-connection-within-servlet-to-the-same-container-tf2620595.html#a7352221
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: socket connection within servlet to the same container

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dmitry,

Dmitry Kandalov wrote:
> Say I have code like this:
> [snip]
>         socket = new Socket( request.getLocalAddr(), request.getLocalPort()
> );
>         socket.getOutputStream().write( requestString.getBytes( "ISO-8859-1"
> ) );
>         socket.getOutputStream().write( headersString.getBytes( "ISO-8859-1"
> ) );
>         socket.getInputStream().read(); // <----- it hangs here

Try calling "flush" on your output stream, and possibly even closing it
if you have to.

Any reason not to use java.net.URLConnection for this?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFWHJc9CaO5/Lv0PARAhYGAJ4kIwmkMknbHRySI9qeyfcyq9H8wwCguTov
TQkXKOaix126+pZc0icE+uI=
=lQMl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org