## org.w3c.jigsaw.http.socket
Class SocketClient

    java.lang.Object
      |
      +--org.w3c.jigsaw.http.Client
            |
            +--org.w3c.jigsaw.http.socket.SocketClient

Direct Known Subclasses:
  SSLSocketClient

public class SocketClient
extends Client
implements java.lang.Runnable

This class implements the object that handles client connections. One such object exists per open connections at any given time.

The basic architecture is the following: the httpd instance accepts new connections on its port. When such a connection is accepted a Client object is requested to the client pool (which can implement what ever strategy is suitable). Each request is than managed by looking up an resource and invoking the resource methods corresponding to the request.

See Also:
  `httpd`, `Request`, `Reply`

Field Summary
`protected boolean` `alive` Is this client still alive ?
`protected int` `bindcount` Number of times this client was bound to a connection.
`protected org.w3c.jigsaw.http.socket.SocketOutputBuffer` `bufout` Our reusable output buffer.
`protected boolean` `done` are we done?
`protected boolean` `idle` Our we idle (waiting for next request ?)
`protected java.net.Socket` `socket` The socket currently handled by the client.
`protected java.lang.Thread` `thread` The thread that we have been attached to.

Fields inherited from class org.w3c.jigsaw.http.Client
`buffer, cont, debug, identifier, prev_body_count, reqcount, server`

Constructor Summary
`protected` `SocketClient(httpd server, SocketClientFactory pool, SocketClientState state)` Create an empty client, that will be ready to work.

Method Summary
`protected void` `bind(java.net.Socket socket)` SocketClientFactory interface - Bind the socket to this client.
`int` `getBindCount()` Get the total number of times this client was bound to a socket.
`java.net.InetAddress` `getInetAddress()` Client implementation - Get the IP address of this client.
`protected java.lang.Thread` `getThread()` Get the thread powering that client.
`protected boolean` `idleConnection()` Client implementation - The current connection is idle.
`void` `join()` If this client is allocated a thread, join it.
`protected void` `kill(boolean now)` SocketClientFactory interface - Kill this client.
`void` `run()` Run for our newly attached connection.
`protected void` `stopConnection()` Client implementation - This connection has been stopped.
`java.lang.String` `toString()` Print that client into a String.
`protected void` `unbind()` SocketClientFactory interface - Unbind this client.
`protected void` `usedConnection()` Client implementation - The current connection is in use.

Methods inherited from class org.w3c.jigsaw.http.Client
`chunkTransfer, emitReply, error, getIdentifier, getInputStream, getMajorVersion, getMinorVersion, getNextRequest, getOutputStream, getRequestCount, getServer, handleTimerEvent, initialize, interruptConnection, isInterrupted, isRunning, log, processRequest, sendContinue, sendContinue, startConnection, trace, tryKeepConnection`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### socket

    protected java.net.Socket socket

  The socket currently handled by the client.

### alive

    protected boolean alive

  Is this client still alive ?

### bindcount

    protected int bindcount

  Number of times this client was bound to a connection.

### thread

    protected java.lang.Thread thread

  The thread that we have been attached to.

### bufout

    protected org.w3c.jigsaw.http.socket.SocketOutputBuffer bufout

  Our reusable output buffer.

### idle

    protected boolean idle

  Our we idle (waiting for next request ?)

### done

    protected boolean done

  are we done?

Constructor Detail

### SocketClient

    protected SocketClient(httpd server,
                           SocketClientFactory pool,
                           SocketClientState state)

  Create an empty client, that will be ready to work. The created client will run and wait for it to be `bind` to some socket before proceeding.
  Parameters:
    `server` - The server to which this client is attached.
    `id` - The client identifier.
  See Also:
    `Client`, `ClientFactory`

Method Detail

### toString

    public java.lang.String toString()

  Print that client into a String.
  Overrides:
    toString in class java.lang.Object
  Returns:
    A String instance.

### join

    public void join()

  If this client is allocated a thread, join it.

### run

    public void run()

  Run for our newly attached connection.
  Specified by:
    run in interface java.lang.Runnable
  Returns:
    A boolean, true if the client is to be killed as decided by its SocketClientFactory creator.

### getInetAddress

    public java.net.InetAddress getInetAddress()

  Client implementation - Get the IP address of this client.
  Overrides:
    getInetAddress in class Client
  Returns:
    An InetAddress instance, or null if the client is not currently running.

### stopConnection

    protected void stopConnection()

  Client implementation - This connection has been stopped. Make sure the whole socket is closed, and be ready to handle next connection.
  Overrides:
    stopConnection in class Client

### getThread

    protected java.lang.Thread getThread()

  Get the thread powering that client.
  Overrides:
    getThread in class Client
  Returns:
    A Thread instance, or null.

### idleConnection

    protected boolean idleConnection()

  Client implementation - The current connection is idle. The client is about to wait for the next request from the net, mark it as idle to make it a candidate for persistent connection closing.
  Overrides:
    idleConnection in class Client
  Returns:
    A boolean, if true our client factory wants us to stop right now, in order to handle some other connection.

### usedConnection

    protected void usedConnection()

  Client implementation - The current connection is in use. A request is about to be processed, mark that connection as used, to remove it from the idle state.
  Overrides:
    usedConnection in class Client

### bind

    protected void bind(java.net.Socket socket)

  SocketClientFactory interface - Bind the socket to this client. Binding a socket to a client triggers the processing of the underlying connection. It is assumed that the client was ready to handle a new connection before this method was called.
  Parameters:
    `socket` - The socket this client should now handle.

### unbind

    protected void unbind()

  SocketClientFactory interface - Unbind this client. This client is handling an idle connection, unbind it to make it free for handling some other more buzy connection.

### kill

    protected void kill(boolean now)

  SocketClientFactory interface - Kill this client. The clean way for our client factory to shut us down unconditionally. This will free all resources acquired by this client, stop the current connection processing if needed, and terminate the underlying thread.

### getBindCount

    public final int getBindCount()

  Get the total number of times this client was bound to a socket.
  Returns:
    An integer, indicatingthe number of bind calls on this client.