java.net
Class SocketImpl
java.lang.Object
|
+--java.net.SocketImpl
All Implemented Interfaces:
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:- Aaron M. Renn (arenn@urbanophile.com)
- Per Bothner <bothner@cygnus.com>
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
SocketImpl
public SocketImpl()
Default, no-argument constructor for use by subclasses.
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:
- The number of readable bytes before blocking
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:
- A FileDescriptor for this socket.
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:
- An
InputStream
for reading from this socket.
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:
- The current value of the option
Throws:
getOutputStream
protected OutputStream getOutputStream()
Returns an OutputStream
object for writing to this socket
Returns:
- An
OutputStream
for writing to this socket.
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:
- A
String
for this socket.
A default implementation is provided by the system, but this can be changed via installing a
SocketImplFactory
(through a call to the static methodSocket.setSocketImplFactory
). A subclass ofSocket
can also pass in aSocketImpl
to theSocket(SocketImpl)
constructor to use an implementation different from the system default without installing a factory.