Android
java.net
public abstract class

java.net.SocketImpl

java.lang.Object
java.net.SocketImpl SocketOptions

The abstract superclass of all classes that implement streaming sockets. Streaming sockets are wrapped by two classes, ServerSocket and Socket at the server and client end of a connection respectively. At the server there are two types of sockets engaged in communication, the ServerSocket on a well known port (hereafter refered to as the listener) used to establish a connection and the resulting Socket (hereafter refered to as host). Some of the SocketImpl instance variable values must be interpreted in the context of the wrapper. See the getter methods for these details.

Summary

Constants inherited from interface java.net.SocketOptions

Fields

protected      InetAddress  address   
protected      FileDescriptor  fd   
protected      int  localport   
protected      int  port   
protected      int  receiveTimeout   

Public Constructors

            SocketImpl()
Construct a connection-oriented SocketImpl.

Public Methods

abstract          Object  getOption(int optID)
Answer the nominated socket option.
abstract          void  setOption(int optID, Object val)
Set the nominated socket option.
          String  toString()
Returns a string containing a concise, human-readable description of the socket.

Protected Methods

abstract          void  accept(SocketImpl newSocket)
Accepts a connection on the provided socket.
abstract          int  available()
Answer the number of bytes that may be read from this socket without blocking.
abstract          void  bind(InetAddress address, int port)
Binds this socket to the specified local host/port.
abstract          void  close()
Close the socket.
abstract          void  connect(SocketAddress remoteAddr, int timeout)
Connect the socket to the host/port specified by the SocketAddress with a specified timeout.
abstract          void  connect(InetAddress address, int port)
Connects this socket to the specified remote host address/port.
abstract          void  connect(String host, int port)
Connects this socket to the specified remote host/port.
abstract          void  create(boolean isStreaming)
Creates a new unconnected socket.
          FileDescriptor  getFileDescriptor()
Answer the socket's file descriptor.
          InetAddress  getInetAddress()
Answer the socket's address.
abstract          InputStream  getInputStream()
Answer the socket input stream.
          int  getLocalPort()
Answer the socket's localport.
abstract          OutputStream  getOutputStream()
Answer the socket output stream.
          int  getPort()
Answer the socket's remote port.
abstract          void  listen(int backlog)
Listen for connection requests on this stream socket.
abstract          void  sendUrgentData(int value)
Send the single byte of urgent data on the socket.
          void  setPerformancePreferences(int connectionTime, int latency, int bandwidth)
Sets performance preference for connectionTime, latency and bandwidth.
          void  shutdownInput()
Shutdown the input portion of the socket.
          void  shutdownOutput()
Shutdown the output portion of the socket.
          boolean  supportsUrgentData()
Answer if the socket supports urgent data.
Methods inherited from class java.lang.Object
Methods inherited from interface java.net.SocketOptions

Details

Fields

protected InetAddress address

protected FileDescriptor fd

protected int localport

protected int port

protected int receiveTimeout

Public Constructors

public SocketImpl()

Construct a connection-oriented SocketImpl.

Public Methods

public abstract Object getOption(int optID)

Answer the nominated socket option.

Parameters

optID the socket option to retrieve

Returns

  • Object the option value

Throws

SocketException thrown if an error occurs while accessing the option

public abstract void setOption(int optID, Object val)

Set the nominated socket option.

Parameters

optID the socket option to set
val the option value

Throws

SocketException thrown if an error occurs while setting the option

public String toString()

Returns a string containing a concise, human-readable description of the socket.

Returns

  • String the description

Protected Methods

protected abstract void accept(SocketImpl newSocket)

Accepts a connection on the provided socket.

Parameters

newSocket the socket to accept connections on

Throws

SocketException if an error occurs while accepting
IOException

protected abstract int available()

Answer the number of bytes that may be read from this socket without blocking. This call does not block.

Returns

  • int the number of bytes that may be read without blocking

Throws

SocketException if an error occurs while peeking
IOException

protected abstract void bind(InetAddress address, int port)

Binds this socket to the specified local host/port.

Parameters

address the local machine address to bind the socket to
port the port on the local machine to bind the socket to

Throws

IOException if an error occurs while binding

protected abstract void close()

Close the socket. Usage thereafter is invalid.

Throws

IOException if an error occurs while closing

protected abstract void connect(SocketAddress remoteAddr, int timeout)

Connect the socket to the host/port specified by the SocketAddress with a specified timeout.

Parameters

remoteAddr the remote machine address and port to connect to
timeout the millisecond timeout value, the connect will block indefinitely for a zero value.

Throws

IOException if a problem occurs during the connect

protected abstract void connect(InetAddress address, int port)

Connects this socket to the specified remote host address/port.

Parameters

address the remote host address to connect to
port the remote port to connect to

Throws

IOException if an error occurs while connecting

protected abstract void connect(String host, int port)

Connects this socket to the specified remote host/port.

Parameters

host the remote host to connect to
port the remote port to connect to

Throws

IOException if an error occurs while connecting

protected abstract void create(boolean isStreaming)

Creates a new unconnected socket. If streaming is true, create a stream socket, else a datagram socket.

Parameters

isStreaming true, if the socket is type streaming

Throws

SocketException if an error occurs while creating the socket
IOException

protected FileDescriptor getFileDescriptor()

Answer the socket's file descriptor.

Returns

  • FileDescriptor the socket FileDescriptor

protected InetAddress getInetAddress()

Answer the socket's address. Refering to the class comment: Listener: The local machines IP address to which this socket is bound. Host: The client machine, to which this socket is connected. Client: The host machine, to which this socket is connected.

Returns

  • InetAddress the socket address

protected abstract InputStream getInputStream()

Answer the socket input stream.

Returns

  • InputStream an InputStream on the socket

Throws

IOException thrown if an error occurs while accessing the stream

protected int getLocalPort()

Answer the socket's localport. The field is initialized to -1 and upon demand will go to the IP stack to get the bound value. See the class comment for the context of the local port.

Returns

  • int the socket localport

protected abstract OutputStream getOutputStream()

Answer the socket output stream.

Returns

  • OutputStream an OutputStream on the socket

Throws

IOException thrown if an error occurs while accessing the stream

protected int getPort()

Answer the socket's remote port. This value is not meaningful when the socketImpl is wrapped by a ServerSocket.

Returns

  • int the remote port the socket is connected to

protected abstract void listen(int backlog)

Listen for connection requests on this stream socket. Incoming connection requests are queued, up to the limit nominated by backlog. Additional requests are rejected. listen() may only be invoked on stream sockets.

Parameters

backlog the max number of outstanding connection requests

Throws

IOException thrown if an error occurs while listening

protected abstract void sendUrgentData(int value)

Send the single byte of urgent data on the socket.

Parameters

value the byte of urgent data

Throws

IOException when an error occurs sending urgent data

protected void setPerformancePreferences(int connectionTime, int latency, int bandwidth)

Sets performance preference for connectionTime, latency and bandwidth. Does nothing by default.

Parameters

connectionTime the importance of connect time
latency the importance of latency
bandwidth the importance of bandwidth

protected void shutdownInput()

Shutdown the input portion of the socket. The default implementation always throws an IOException to indicate that the subclass should have overridden this method.

Throws

IOException Always. Designed to be subclassed.

protected void shutdownOutput()

Shutdown the output portion of the socket. The default implementation always throws an IOException to indicate that the subclass should have overridden this method.

Throws

IOException Always. Designed to be subclassed.

protected boolean supportsUrgentData()

Answer if the socket supports urgent data. Subclasses should override this method.

Returns

  • false, subclasses must override
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48