public abstract class SocketImpl extends Object implements SocketOptions
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).Modifier and Type | Field and Description |
---|---|
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.
|
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
Constructor and Description |
---|
SocketImpl() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
accept(SocketImpl newSocket)
Waits for an incoming request and blocks until the connection is opened
on the given socket.
|
protected abstract int |
available()
Returns the available number of bytes which are readable from this socket
without blocking.
|
protected abstract void |
bind(InetAddress address,
int port)
Binds this socket to the specified local host address and port number.
|
protected abstract void |
close()
Closes this socket.
|
protected abstract void |
connect(InetAddress address,
int port)
Connects this socket to the specified remote host address and port
number.
|
protected 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. |
protected abstract void |
connect(String host,
int port)
Connects this socket to the specified remote host and port number.
|
protected abstract void |
create(boolean isStreaming)
Creates a new unconnected socket.
|
FileDescriptor |
getFD$() |
protected FileDescriptor |
getFileDescriptor()
Gets the file descriptor of this socket.
|
protected InetAddress |
getInetAddress()
Gets the remote address this socket is connected to.
|
protected abstract InputStream |
getInputStream()
Gets the input stream of this socket.
|
protected int |
getLocalPort()
Gets the local port number of this socket.
|
protected abstract OutputStream |
getOutputStream()
Gets the output stream of this socket.
|
protected int |
getPort()
Gets the remote port number of this socket.
|
protected abstract void |
listen(int backlog)
Listens for connection requests on this streaming socket.
|
protected abstract void |
sendUrgentData(int value)
Sends the single byte of urgent data on the socket.
|
protected void |
setPerformancePreferences(int connectionTime,
int latency,
int bandwidth)
Sets performance preference for connection time, latency and bandwidth.
|
protected void |
shutdownInput()
Closes the input channel of this socket.
|
protected void |
shutdownOutput()
Closes the output channel of this socket.
|
protected boolean |
supportsUrgentData()
Returns whether the socket supports urgent data or not.
|
String |
toString()
Returns a string containing a concise, human-readable description of the
socket.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getOption, setOption
protected InetAddress address
protected int port
protected FileDescriptor fd
protected int localport
protected abstract void accept(SocketImpl newSocket) throws IOException
newSocket
- the socket to accept connections on.IOException
- if an error occurs while accepting a new connection.protected abstract int available() throws IOException
IOException
- if an error occurs while reading the number of bytes.protected abstract void bind(InetAddress address, int port) throws IOException
address
- the local machine address to bind this socket to.port
- the port on the local machine to bind this socket to.IOException
- if an error occurs while binding this socket.protected abstract void close() throws IOException
IOException
- if an error occurs while closing this socket.protected abstract void connect(String host, int port) throws IOException
host
- the remote host this socket has to be connected to.port
- the remote port on which this socket has to be connected.IOException
- if an error occurs while connecting to the remote host.protected abstract void connect(InetAddress address, int port) throws IOException
address
- the remote host address this socket has to be connected to.port
- the remote port on which this socket has to be connected.IOException
- if an error occurs while connecting to the remote host.protected abstract void create(boolean isStreaming) throws IOException
isStreaming
defines whether the new socket is a streaming or a datagram socket.isStreaming
- defines whether the type of the new socket is streaming or
datagram.IOException
- if an error occurs while creating the socket.protected FileDescriptor getFileDescriptor()
public FileDescriptor getFD$()
protected InetAddress getInetAddress()
protected abstract InputStream getInputStream() throws IOException
IOException
- if an error occurs while accessing the input stream.protected int getLocalPort()
-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.protected abstract OutputStream getOutputStream() throws IOException
IOException
- if an error occurs while accessing the output stream.protected int getPort()
ServerSocket
.protected abstract void listen(int backlog) throws IOException
backlog
. Additional requests are rejected. This method
may only be invoked on stream sockets.backlog
- the maximum number of outstanding connection requests.IOException
- if an error occurs while listening.public String toString()
protected void shutdownInput() throws IOException
This default implementation always throws an IOException
to
indicate that the subclass should have overridden this method.
IOException
- always because this method should be overridden.protected void shutdownOutput() throws IOException
This default implementation always throws an IOException
to
indicate that the subclass should have overridden this method.
IOException
- always because this method should be overridden.protected abstract void connect(SocketAddress remoteAddr, int timeout) throws IOException
SocketAddress
object with the given timeout. This method
will block indefinitely if the timeout is set to zero.remoteAddr
- the remote host address and port number to connect to.timeout
- the timeout value in milliseconds.IOException
- if an error occurs while connecting.protected boolean supportsUrgentData()
false
because subclasses must override this method.protected abstract void sendUrgentData(int value) throws IOException
value
- the byte of urgent data.IOException
- if an error occurs sending urgent data.protected void setPerformancePreferences(int connectionTime, int latency, int bandwidth)
connectionTime
- the importance of connect time.latency
- the importance of latency.bandwidth
- the importance of bandwidth.