Skip to content

Most visited

Recently visited

navigation
Added in API level 1

SocketImpl

public abstract class SocketImpl
extends Object implements SocketOptions

java.lang.Object
   ↳ java.net.SocketImpl


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

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.

Inherited methods

From class java.lang.Object
From interface java.net.SocketOptions

Fields

address

Added in API level 1
InetAddress address

The remote address this socket is connected to.

fd

Added in API level 1
FileDescriptor fd

The file descriptor of this socket.

localport

Added in API level 1
int localport

The local port this socket is connected to.

port

Added in API level 1
int port

The remote port this socket is connected to.

Public constructors

SocketImpl

Added in API level 1
SocketImpl ()

Public methods

toString

Added in API level 1
String toString ()

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

Returns
String the textual representation of this socket.

Protected methods

accept

Added in API level 1
void accept (SocketImpl newSocket)

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

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

available

Added in API level 1
int available ()

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

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

bind

Added in API level 1
void bind (InetAddress address, 
                int port)

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

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

close

Added in API level 1
void close ()

Closes this socket. This makes later access invalid.

Throws
IOException if an error occurs while closing this socket.

connect

Added in API level 1
void connect (InetAddress address, 
                int port)

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

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

connect

Added in API level 1
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. This method will block indefinitely if the timeout is set to zero.

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

connect

Added in API level 1
void connect (String host, 
                int port)

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

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

create

Added in API level 1
void create (boolean isStreaming)

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

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

getFileDescriptor

Added in API level 1
FileDescriptor getFileDescriptor ()

Gets the file descriptor of this socket.

Returns
FileDescriptor the file descriptor of this socket.

getInetAddress

Added in API level 1
InetAddress getInetAddress ()

Gets the remote address this socket is connected to.

Returns
InetAddress the remote address of this socket.

getInputStream

Added in API level 1
InputStream getInputStream ()

Gets the input stream of this socket.

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

getLocalPort

Added in API level 1
int getLocalPort ()

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

getOutputStream

Added in API level 1
OutputStream getOutputStream ()

Gets the output stream of this socket.

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

getPort

Added in API level 1
int getPort ()

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

Returns
int the remote port this socket is connected to.

listen

Added in API level 1
void listen (int backlog)

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 int: the maximum number of outstanding connection requests.
Throws
IOException if an error occurs while listening.

sendUrgentData

Added in API level 1
void sendUrgentData (int value)

Sends the single byte of urgent data on the socket.

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

setPerformancePreferences

Added in API level 1
void setPerformancePreferences (int connectionTime, 
                int latency, 
                int bandwidth)

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

Parameters
connectionTime int: the importance of connect time.
latency int: the importance of latency.
bandwidth int: the importance of bandwidth.

shutdownInput

Added in API level 1
void shutdownInput ()

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.

shutdownOutput

Added in API level 1
void shutdownOutput ()

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.

supportsUrgentData

Added in API level 1
boolean supportsUrgentData ()

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

Returns
boolean false because subclasses must override this method.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.