public class

SocketHttpClientConnection

extends AbstractHttpClientConnection
implements HttpInetConnection
java.lang.Object
   ↳ org.apache.http.impl.AbstractHttpClientConnection
     ↳ org.apache.http.impl.SocketHttpClientConnection
Known Direct Subclasses

Class Overview

Implementation of a client-side HTTP connection that can be bound to an arbitrary Socket for receiving data from and transmitting data to a remote server.

The following parameters can be used to customize the behavior of this class:

Summary

Public Constructors
SocketHttpClientConnection()
Public Methods
void close()
Closes this connection gracefully.
InetAddress getLocalAddress()
int getLocalPort()
InetAddress getRemoteAddress()
int getRemotePort()
int getSocketTimeout()
Returns the socket timeout value.
boolean isOpen()
Checks if this connection is open.
void setSocketTimeout(int timeout)
Sets the socket timeout value.
void shutdown()
Force-closes this connection.
Protected Methods
void assertNotOpen()
void assertOpen()
Asserts if the connection is open.
void bind(Socket socket, HttpParams params)
Binds this connection to the given Socket.
SessionInputBuffer createSessionInputBuffer(Socket socket, int buffersize, HttpParams params)
Creates an instance of SocketInputBuffer to be used for receiving data from the given Socket.
SessionOutputBuffer createSessionOutputBuffer(Socket socket, int buffersize, HttpParams params)
Creates an instance of SessionOutputBuffer to be used for sending data to the given Socket.
Socket getSocket()
[Expand]
Inherited Methods
From class org.apache.http.impl.AbstractHttpClientConnection
From class java.lang.Object
From interface org.apache.http.HttpClientConnection
From interface org.apache.http.HttpConnection
From interface org.apache.http.HttpInetConnection

Public Constructors

public SocketHttpClientConnection ()

Public Methods

public void close ()

Closes this connection gracefully. This method will attempt to flush the internal output buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Use shutdown instead.

Throws
IOException

public InetAddress getLocalAddress ()

public int getLocalPort ()

public InetAddress getRemoteAddress ()

public int getRemotePort ()

public int getSocketTimeout ()

Returns the socket timeout value.

Returns
  • positive value in milliseconds if a timeout is set, 0 if timeout is disabled or -1 if timeout is undefined.

public boolean isOpen ()

Checks if this connection is open.

Returns
  • true if it is open, false if it is closed.

public void setSocketTimeout (int timeout)

Sets the socket timeout value.

Parameters
timeout timeout value in milliseconds

public void shutdown ()

Force-closes this connection. This is the only method of a connection which may be called from a different thread to terminate the connection. This method will not attempt to flush the transmitter's internal buffer prior to closing the underlying socket.

Throws
IOException

Protected Methods

protected void assertNotOpen ()

protected void assertOpen ()

Asserts if the connection is open.

protected void bind (Socket socket, HttpParams params)

Binds this connection to the given Socket. This socket will be used by the connection to send and receive data.

This method will invoke createSessionInputBuffer(Socket, int, HttpParams) and createSessionOutputBuffer(Socket, int, HttpParams) methods to create session input / output buffers bound to this socket and then will invoke init(SessionInputBuffer, SessionOutputBuffer, HttpParams) method to pass references to those buffers to the underlying HTTP message parser and formatter.

After this method's execution the connection status will be reported as open and the isOpen() will return true.

Parameters
socket the socket.
params HTTP parameters.
Throws
IOException in case of an I/O error.

protected SessionInputBuffer createSessionInputBuffer (Socket socket, int buffersize, HttpParams params)

Creates an instance of SocketInputBuffer to be used for receiving data from the given Socket.

This method can be overridden in a super class in order to provide a custom implementation of SessionInputBuffer interface.

Parameters
socket the socket.
buffersize the buffer size.
params HTTP parameters.
Returns
  • session input buffer.
Throws
IOException in case of an I/O error.

protected SessionOutputBuffer createSessionOutputBuffer (Socket socket, int buffersize, HttpParams params)

Creates an instance of SessionOutputBuffer to be used for sending data to the given Socket.

This method can be overridden in a super class in order to provide a custom implementation of SocketOutputBuffer interface.

Parameters
socket the socket.
buffersize the buffer size.
params HTTP parameters.
Returns
  • session output buffer.
Throws
IOException in case of an I/O error.

protected Socket getSocket ()