public abstract class SocketImpl extends Object implements SocketOptions
SocketImpl是实际实现套接字的所有类的公共超类。
它用于创建客户端和服务器套接字。
“plain”套接字完全按照所描述的方式实现这些方法,而不尝试通过防火墙或代理。
| Modifier and Type | Field and Description |
|---|---|
protected InetAddress |
address
该套接字远端的IP地址。
|
protected FileDescriptor |
fd
该套接字的文件描述符对象。
|
protected int |
localport
此套接字连接到的本地端口号。
|
protected int |
port
此套接字连接到的远程主机上的端口号。
|
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 s)
接受连接。
|
protected abstract int |
available()
返回可从该套接字读取而不阻塞的字节数。
|
protected abstract void |
bind(InetAddress host, int port)
将此套接字绑定到指定的本地IP地址和端口号。
|
protected abstract void |
close()
关闭此套接字。
|
protected abstract void |
connect(InetAddress address, int port)
将此套接字连接到指定主机上的指定端口号。
|
protected abstract void |
connect(SocketAddress address, int timeout)
将此套接字连接到指定主机上的指定端口号。
|
protected abstract void |
connect(String host, int port)
将此套接字连接到指定主机上的指定端口。
|
protected abstract void |
create(boolean stream)
创建流或数据报套接字。
|
protected FileDescriptor |
getFileDescriptor()
返回此套接字的
fd字段的值。
|
protected InetAddress |
getInetAddress()
返回此套接字的
address字段的值。
|
protected abstract InputStream |
getInputStream()
返回此套接字的输入流。
|
protected int |
getLocalPort()
返回此套接字的
localport字段的值。
|
protected abstract OutputStream |
getOutputStream()
返回此套接字的输出流。
|
protected int |
getPort()
返回此套接字
port字段的值。
|
protected abstract void |
listen(int backlog)
将传入连接指示(请求连接)的最大队列长度设置为
count参数。
|
protected abstract void |
sendUrgentData(int data)
在套接字上发送一个字节的紧急数据。
|
protected void |
setPerformancePreferences(int connectionTime, int latency, int bandwidth)
设置此套接字的性能首选项。
|
protected void |
shutdownInput()
将此套接字的输入流放置在“流的末尾”。
|
protected void |
shutdownOutput()
禁用此套接字的输出流。
|
protected boolean |
supportsUrgentData()
返回SocketImpl是否支持发送紧急数据。
|
String |
toString()
以
String形式返回此套接字的地址和端口。
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetOption, setOptionprotected FileDescriptor fd
protected InetAddress address
protected int port
protected int localport
protected abstract void create(boolean stream)
throws IOException
stream - 如果true ,创建一个流套接字;
否则,创建一个数据报套接字。
IOException - 如果在创建套接字时发生I / O错误。
protected abstract void connect(String host, int port) throws IOException
host - 远程主机的名称。
port - 端口号。
IOException - 如果连接到远程主机时发生I / O错误。
protected abstract void connect(InetAddress address, int port) throws IOException
address - 远程主机的IP地址。
port - 端口号。
IOException - 如果尝试连接时发生I / O错误。
protected abstract void connect(SocketAddress address, int timeout) throws IOException
address - 远程主机的Socket地址。
timeout - 无超时的超时值(以毫秒为单位)或零。
IOException - 如果尝试连接时发生I / O错误。
protected abstract void bind(InetAddress host, int port) throws IOException
host - 属于本地接口的IP地址。
port - 端口号。
IOException - 绑定此套接字时是否发生I / O错误。
protected abstract void listen(int backlog)
throws IOException
count参数。
如果连接指示在队列已满时到达,则连接被拒绝。
backlog - 队列的最大长度。
IOException - 如果在创建队列时发生I / O错误。
protected abstract void accept(SocketImpl s) throws IOException
s - 接受的连接。
IOException - 如果接受连接时发生I / O错误。
protected abstract InputStream getInputStream() throws IOException
IOException - 如果在创建输入流时发生I / O错误。
protected abstract OutputStream getOutputStream() throws IOException
IOException - 如果在创建输出流时发生I / O错误。
protected abstract int available()
throws IOException
IOException - 如果在确定可用字节数时发生I / O错误。
protected abstract void close()
throws IOException
IOException - 如果在关闭此套接字时发生I / O错误。
protected void shutdownInput()
throws IOException
available方法将返回0,其read方法将返回-1 (流结尾)。
IOException - 如果在关闭此套接字时发生I / O错误。
Socket.shutdownOutput() ,
Socket.close() ,
Socket.setSoLinger(boolean, int)
protected void shutdownOutput()
throws IOException
IOException - 如果在关闭此套接字时发生I / O错误。
Socket.shutdownInput() ,
Socket.close() ,
Socket.setSoLinger(boolean, int)
protected FileDescriptor getFileDescriptor()
fd字段的值。
fd字段。
fd
protected InetAddress getInetAddress()
address字段的值。
address字段。
address
protected int getPort()
port字段的值。
port字段。
port
protected boolean supportsUrgentData()
address
protected abstract void sendUrgentData(int data)
throws IOException
data - 要发送的数据字节
IOException - 发送数据是否有错误。
protected int getLocalPort()
localport字段的值。
localport字段。
localport
protected void setPerformancePreferences(int connectionTime,
int latency,
int bandwidth)
套接字默认使用TCP / IP协议。 一些实现可以提供具有与TCP / IP不同的性能特征的替代协议。 该方法允许应用程序表达自己的偏好,以便在实现从可用协议中选择时应如何进行这些权衡。
性能偏好由三个整数描述,其值表示短连接时间,低延迟和高带宽的相对重要性。 整数的绝对值是无关紧要的; 为了选择协议,简单地比较值,较大的值表示较强的偏好。 负值表示比正值低的优先级。 例如,如果应用程序优先考虑低延迟和高带宽的短连接时间,则可以使用值(1, 0, 0)调用此方法。 如果应用程序优先于低延迟的高带宽,并且在短的连接时间以上的低延迟,则可以使用值(0, 1, 2)调用此方法。 默认情况下,此方法不执行任何操作,除非在aa子类中被覆盖。
connectionTime -一个
int表达短连接时间的相对重要性
latency -
int低延迟的相对重要性的int
bandwidth -一个
int表达高带宽的相对重要性
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.