public abstract class

SocketImpl

extends Object
implements SocketOptions
java.lang.Object
   ↳ java.net.SocketImpl

Class Overview

This class is the base of all streaming socket implementation classes. Streaming sockets are wrapped by two classes, ServerSocket and Socket at the server and client end of a connection. At the server, there are two types of sockets engaged in communication, the ServerSocket on a well known port (referred to as listener) used to establish a connection and the resulting Socket (referred to as host).

Summary

[Expand]
Inherited Constants
From interface java.net.SocketOptions
Fields
protected InetAddress address The remote address this socket is connected to.
protected FileDescriptor fd The file descriptor of this socket.
protected int localport The local port this socket is connected to.
protected int port The remote port this socket is connected to.
Public Constructors
SocketImpl()
Public Methods
String toString()
Returns a string containing a concise, human-readable description of the socket.
Protected Methods
abstract void accept(SocketImpl newSocket)
Waits for an incoming request and blocks until the connection is opened on the given socket.
abstract int available()
Returns the available number of bytes which are readable from this socket without blocking.
abstract void bind(InetAddress address, int port)
Binds this socket to the specified local host address and port number.
abstract void close()
Closes this socket.
abstract void connect(InetAddress address, int port)
Connects this socket to the specified remote host address and port number.
abstract void connect(SocketAddress remoteAddr, int timeout)
Connects this socket to the remote host address and port number specified by the SocketAddress object with the given timeout.
abstract void connect(String host, int port)
Connects this socket to the specified remote host and port number.
abstract void create(boolean isStreaming)
Creates a new unconnected socket.
FileDescriptor getFileDescriptor()
Gets the file descriptor of this socket.
InetAddress getInetAddress()
Gets the remote address this socket is connected to.
abstract InputStream getInputStream()
Gets the input stream of this socket.
int getLocalPort()
Gets the local port number of this socket.
abstract OutputStream getOutputStream()
Gets the output stream of this socket.
int getPort()
Gets the remote port number of this socket.
abstract void listen(int backlog)
Listens for connection requests on this streaming socket.
abstract void sendUrgentData(int value)
Sends the single byte of urgent data on the socket.
void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
Sets performance preference for connection time, latency and bandwidth.
void shutdownInput()
Closes the input channel of this socket.
void shutdownOutput()
Closes the output channel of this socket.
boolean supportsUrgentData()
Returns whether the socket supports urgent data or not.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.net.SocketOptions

Fields

protected InetAddress address

Since: API Level 1

The remote address this socket is connected to.

protected FileDescriptor fd

Since: API Level 1

The file descriptor of this socket.

protected int localport

Since: API Level 1

The local port this socket is connected to.

protected int port

Since: API Level 1

The remote port this socket is connected to.

Public Constructors

public SocketImpl ()

Since: API Level 1

Public Methods

public String toString ()

Since: API Level 1

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

Returns
  • the textual representation of this socket.

Protected Methods

protected abstract void accept (SocketImpl newSocket)

Since: API Level 1

Waits for an incoming request and blocks until the connection is opened on the given socket.

Parameters
newSocket the socket to accept connections on.
Throws
IOException if an error occurs while accepting a new connection.

protected abstract int available ()

Since: API Level 1

Returns the available number of bytes which are readable from this socket without blocking.

Returns
  • the number of bytes that may be read without blocking.
Throws
IOException if an error occurs while reading the number of bytes.

protected abstract void bind (InetAddress address, int port)

Since: API Level 1

Binds this socket to the specified local host address and port number.

Parameters
address the local machine address to bind this socket to.
port the port on the local machine to bind this socket to.
Throws
IOException if an error occurs while binding this socket.

protected abstract void close ()

Since: API Level 1

Closes this socket. This makes later access invalid.

Throws
IOException if an error occurs while closing this socket.

protected abstract void connect (InetAddress address, int port)

Since: API Level 1

Connects this socket to the specified remote host address and port number.

Parameters
address the remote host address this socket has to be connected to.
port the remote port on which this socket has to be connected.
Throws
IOException if an error occurs while connecting to the remote host.

protected abstract void connect (SocketAddress remoteAddr, int timeout)

Since: API Level 1

Connects this socket to the remote host address and port number specified by the SocketAddress object with the given timeout. This method will block indefinitely if the timeout is set to zero.

Parameters
remoteAddr the remote host address and port number to connect to.
timeout the timeout value in milliseconds.
Throws
IOException if an error occurs while connecting.

protected abstract void connect (String host, int port)

Since: API Level 1

Connects this socket to the specified remote host and port number.

Parameters
host the remote host this socket has to be connected to.
port the remote port on which this socket has to be connected.
Throws
IOException if an error occurs while connecting to the remote host.

protected abstract void create (boolean isStreaming)

Since: API Level 1

Creates a new unconnected socket. The argument isStreaming defines whether the new socket is a streaming or a datagram socket.

Parameters
isStreaming defines whether the type of the new socket is streaming or datagram.
Throws
IOException if an error occurs while creating the socket.

protected FileDescriptor getFileDescriptor ()

Since: API Level 1

Gets the file descriptor of this socket.

Returns
  • the file descriptor of this socket.

protected InetAddress getInetAddress ()

Since: API Level 1

Gets the remote address this socket is connected to.

Returns
  • the remote address of this socket.

protected abstract InputStream getInputStream ()

Since: API Level 1

Gets the input stream of this socket.

Returns
  • the input stream of this socket.
Throws
IOException if an error occurs while accessing the input stream.

protected int getLocalPort ()

Since: API Level 1

Gets the local port number of this socket. 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
  • the local port number this socket is bound to.

protected abstract OutputStream getOutputStream ()

Since: API Level 1

Gets the output stream of this socket.

Returns
  • the output stream of this socket.
Throws
IOException if an error occurs while accessing the output stream.

protected int getPort ()

Since: API Level 1

Gets the remote port number of this socket. This value is not meaningful when this instance is wrapped by a ServerSocket.

Returns
  • the remote port this socket is connected to.

protected abstract void listen (int backlog)

Since: API Level 1

Listens for connection requests on this streaming socket. Incoming connection requests are queued up to the limit specified by backlog. Additional requests are rejected. This method may only be invoked on stream sockets.

Parameters
backlog the maximum number of outstanding connection requests.
Throws
IOException if an error occurs while listening.

protected abstract void sendUrgentData (int value)

Since: API Level 1

Sends the single byte of urgent data on the socket.

Parameters
value the byte of urgent data.
Throws
IOException if an error occurs sending urgent data.

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

Since: API Level 1

Sets performance preference for connection time, 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 ()

Since: API Level 1

Closes the input channel of this socket.

This default implementation always throws an IOException to indicate that the subclass should have overridden this method.

Throws
IOException always because this method should be overridden.

protected void shutdownOutput ()

Since: API Level 1

Closes the output channel of this socket.

This default implementation always throws an IOException to indicate that the subclass should have overridden this method.

Throws
IOException always because this method should be overridden.

protected boolean supportsUrgentData ()

Since: API Level 1

Returns whether the socket supports urgent data or not. Subclasses should override this method.

Returns
  • false because subclasses must override this method.