Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.net

Class SocketImpl

java.lang.Object
|
+--java.net.SocketImpl

All Implemented Interfaces:

SocketOptions


public abstract class SocketImpl

extends Object

implements SocketOptions

This abstract class serves as the parent class for socket implementations. The implementation class serves an intermediary to native routines that perform system specific socket operations.

A default implementation is provided by the system, but this can be changed via installing a SocketImplFactory (through a call to the static method Socket.setSocketImplFactory). A subclass of Socket can also pass in a SocketImpl to the Socket(SocketImpl) constructor to use an implementation different from the system default without installing a factory.

Authors:

Field Summary

java.net.InetAddressaddress

The address of the remote end of the socket connection
java.io.FileDescriptorfd

A FileDescriptor object representing this socket connection.
intlocalport

The port number the socket is bound to locally
intport

The port number of the remote end of the socket connection

Constructor Summary

SocketImpl()

Default, no-argument constructor for use by subclasses.

Method Summary

voidaccept(java.net.SocketImpl s)

Accepts a connection on this socket.
intavailable()

Returns the number of bytes that the caller can read from this socket without blocking.
voidbind(java.net.InetAddress host, int port)

Binds to the specified port on the specified addr.
voidclose()

Closes the socket.
voidconnect(java.lang.String host, int port)

Connects to the remote hostname and port specified as arguments.
voidconnect(java.net.InetAddress host, int port)

Connects to the remote address and port specified as arguments.
voidconnect(java.net.SocketAddress address, int timeout)

Connects to the socket to the host specified in address.
voidcreate(boolean stream)

Creates a new socket that is not bound to any local address/port and is not connected to any remote address/port.
java.io.FileDescriptorgetFileDescriptor()

Returns the FileDescriptor objects for this socket.
java.net.InetAddressgetInetAddress()

Returns the remote address this socket is connected to
java.io.InputStreamgetInputStream()

Returns an InputStream object for reading from this socket.
intgetLocalPort()

Returns the local port this socket is bound to
java.lang.ObjectgetOption(int option_id)

Returns the current setting of the specified option.
java.io.OutputStreamgetOutputStream()

Returns an OutputStream object for writing to this socket
intgetPort()

Returns the remote port this socket is connected to
voidlisten(int backlog)

Starts listening for connections on a socket.
voidsendUrgentData(int data)

Sends one byte of urgent data to the socket.
voidsetOption(int option_id, java.lang.Object val)

Sets the specified option on a socket to the passed in object.
voidshutdownInput()

Shut down the input side of this socket.
voidshutdownOutput()

Shut down the output side of this socket.
booleansupportsUrgentData()

Returns true or false when this socket supports sending urgent data or not.
java.lang.StringtoString()

Returns a String representing the remote host and port of this socket.

Field Details

address

protected InetAddress address

The address of the remote end of the socket connection


fd

protected FileDescriptor fd

A FileDescriptor object representing this socket connection.


localport

protected int localport

The port number the socket is bound to locally


port

protected int port

The port number of the remote end of the socket connection


Constructor Details

SocketImpl

public SocketImpl()

Default, no-argument constructor for use by subclasses.


Method Details

accept

protected void accept(java.net.SocketImpl s)

Accepts a connection on this socket.

Parameters:

Throws:


available

protected int available()

Returns the number of bytes that the caller can read from this socket without blocking.

Returns:

Throws:


bind

protected void bind(java.net.InetAddress host, int port)

Binds to the specified port on the specified addr. Note that this addr must represent a local IP address.

Note that it is unspecified how to bind to all interfaces on the localhost (INADDR_ANY).

Parameters:

Throws:


close

protected void close()

Closes the socket. This will normally cause any resources, such as the InputStream, OutputStream and associated file descriptors to be freed.

Note that if the SO_LINGER option is set on this socket, then the operation could block.

Throws:


connect

protected void connect(java.lang.String host, int port)

Connects to the remote hostname and port specified as arguments.

Parameters:

Throws:


connect

protected void connect(java.net.InetAddress host, int port)

Connects to the remote address and port specified as arguments.

Parameters:

Throws:


connect

protected void connect(java.net.SocketAddress address, int timeout)

Connects to the socket to the host specified in address. This method blocks until successful connected or the timeout occurs. A timeout of zero means no timout.

Since:Parameters:

Throws:


create

protected void create(boolean stream)

Creates a new socket that is not bound to any local address/port and is not connected to any remote address/port. This will be created as a stream socket if the stream parameter is true, or a datagram socket if the stream parameter is false.

Parameters:

Throws:


getFileDescriptor

protected FileDescriptor getFileDescriptor()

Returns the FileDescriptor objects for this socket.

Returns:


getInetAddress

protected InetAddress getInetAddress()

Returns the remote address this socket is connected to

Returns:


getInputStream

protected InputStream getInputStream()

Returns an InputStream object for reading from this socket.

Returns:

Throws:


getLocalPort

protected int getLocalPort()

Returns the local port this socket is bound to

Returns:


getOption

public Object getOption(int option_id)

Returns the current setting of the specified option. The Object returned will be an Integer for options that have integer values. For options that are set to on or off, a Boolean will be returned. The option_id is one of the defined constants in the superinterface.

Parameters:

Returns:

Throws:


getOutputStream

protected OutputStream getOutputStream()

Returns an OutputStream object for writing to this socket

Returns:

Throws:


getPort

protected int getPort()

Returns the remote port this socket is connected to

Returns:


listen

protected void listen(int backlog)

Starts listening for connections on a socket. The backlog parameter is how many pending connections will queue up waiting to be serviced before being accept'ed. If the queue of pending requests exceeds this number, additional connections will be refused.

Parameters:

Throws:


sendUrgentData

protected void sendUrgentData(int data)

Sends one byte of urgent data to the socket.

Since:Parameters:

Throws:


setOption

public void setOption(int option_id, java.lang.Object val)

Sets the specified option on a socket to the passed in object. For options that take an integer argument, the passed in object is an Integer. For options that are set to on or off, the value passed will be a Boolean. The option_id parameter is one of the defined constants in the superinterface.

Parameters:

Throws:


shutdownInput

protected void shutdownInput()

Shut down the input side of this socket. Subsequent reads will return end-of-file.

Throws:


shutdownOutput

protected void shutdownOutput()

Shut down the output side of this socket. Subsequent writes will fail with an IOException.

Throws:


supportsUrgentData

protected boolean supportsUrgentData()

Returns true or false when this socket supports sending urgent data or not.

Since:

toString

public String toString()

Returns a String representing the remote host and port of this socket.

Returns: