public class

HttpReceiveSocket

extends Socket
implements RMISocketInfo
java.lang.Object
   ↳ java.net.Socket
     ↳ sun.rmi.transport.proxy.HttpReceiveSocket

Class Overview

The HttpReceiveSocket class extends the WrappedSocket class by removing the HTTP protocol packaging from the input stream and formatting the output stream as an HTTP response. NOTES: The output stream must be explicitly closed for the output to be sent, since the HttpResponseOutputStream needs to buffer the entire transmission to be able to fill in the content-length field of the HTTP header. Closing this socket will do this. The constructor blocks until the HTTP protocol header is received. This could be fixed, but I don't think it should be a problem because this object would not be created unless the HttpAwareServerSocket has detected the beginning of the header anyway, so the rest should be there. This socket can only be used to process one POST and reply to it. Another message would be received on a newly accepted socket anyway.

Summary

Fields
protected InputStream in the input stream to return for socket
protected OutputStream out the output stream to return for socket
protected Socket socket the underlying concrete socket
Public Constructors
HttpReceiveSocket(Socket socket, InputStream in, OutputStream out)
Layer on top of a pre-existing Socket object, and use specified input and output streams.
Public Methods
synchronized void close()
Close the socket.
InetAddress getInetAddress()
Get the address to which this socket is connected.
InputStream getInputStream()
Get an InputStream for this socket.
InetAddress getLocalAddress()
Get the local address to which the socket is bound.
int getLocalPort()
Get the local port to which the socket is connected.
OutputStream getOutputStream()
Get an OutputStream for this socket.
int getPort()
Get the remote port to which the socket is connected.
int getSoLinger()
Retrive setting for SO_LINGER.
synchronized int getSoTimeout()
Retrive setting for SO_TIMEOUT.
boolean getTcpNoDelay()
Retrieve whether TCP_NODELAY is enabled.
boolean isReusable()
Indicate that this socket is not reusable.
void setSoLinger(boolean on, int val)
Enable/disable SO_LINGER with the specified linger time.
synchronized void setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout
void setTcpNoDelay(boolean on)
Enable/disable TCP_NODELAY.
String toString()
Return string representation of the socket.
[Expand]
Inherited Methods
From class java.net.Socket
From class java.lang.Object
From interface sun.rmi.transport.proxy.RMISocketInfo

Fields

protected InputStream in

the input stream to return for socket

protected OutputStream out

the output stream to return for socket

protected Socket socket

the underlying concrete socket

Public Constructors

public HttpReceiveSocket (Socket socket, InputStream in, OutputStream out)

Layer on top of a pre-existing Socket object, and use specified input and output streams.

Parameters
socket the pre-existing socket to use
in the InputStream to use for this socket (can be null)
out the OutputStream to use for this socket (can be null)
Throws
IOException

Public Methods

public synchronized void close ()

Close the socket.

Throws
IOException

public InetAddress getInetAddress ()

Get the address to which this socket is connected. "null" is always returned (to indicate an unknown address) because the originating host's IP address cannot be reliably determined: both because the request probably went through a proxy server, and because if it was delivered by a local forwarder (CGI script or servlet), we do NOT want it to appear as if the call is coming from the local host (in case the remote object makes access control decisions based on the "client host" of a remote call; see bugid 4399040).

Returns
  • the remote IP address to which this socket is connected, or null if the socket is not connected.

public InputStream getInputStream ()

Get an InputStream for this socket.

Returns
  • an input stream for reading bytes from this socket.
Throws
IOException

public InetAddress getLocalAddress ()

Get the local address to which the socket is bound.

Returns
  • the local address to which the socket is bound or InetAddress.anyLocalAddress() if the socket is not bound yet.

public int getLocalPort ()

Get the local port to which the socket is connected.

Returns
  • the local port number to which this socket is bound or -1 if the socket is not bound yet.

public OutputStream getOutputStream ()

Get an OutputStream for this socket.

Returns
  • an output stream for writing bytes to this socket.
Throws
IOException

public int getPort ()

Get the remote port to which the socket is connected.

Returns
  • the remote port number to which this socket is connected, or 0 if the socket is not connected yet.

public int getSoLinger ()

Retrive setting for SO_LINGER.

Returns
  • the setting for SO_LINGER.

public synchronized int getSoTimeout ()

Retrive setting for SO_TIMEOUT.

Returns
  • the setting for SO_TIMEOUT

public boolean getTcpNoDelay ()

Retrieve whether TCP_NODELAY is enabled.

Returns
  • a boolean indicating whether or not TCP_NODELAY is enabled.

public boolean isReusable ()

Indicate that this socket is not reusable.

public void setSoLinger (boolean on, int val)

Enable/disable SO_LINGER with the specified linger time.

Parameters
on whether or not to linger on.
val how long to linger for, if on is true.

public synchronized void setSoTimeout (int timeout)

Enable/disable SO_TIMEOUT with the specified timeout

Parameters
timeout the specified timeout, in milliseconds.

public void setTcpNoDelay (boolean on)

Enable/disable TCP_NODELAY.

Parameters
on true to enable TCP_NODELAY, false to disable.

public String toString ()

Return string representation of the socket.

Returns
  • a string representation of this socket.