public abstract class DatagramSocketImpl
extends Object implements SocketOptions
| java.lang.Object | |
| ↳ | java.net.DatagramSocketImpl |
抽象数据报和多播套接字实现基类。
Inherited constants |
|---|
java.net.SocketOptions
|
Fields |
|
|---|---|
protected FileDescriptor |
fd 文件描述符对象。 |
protected int |
localPort 本地端口号。 |
Public constructors |
|
|---|---|
DatagramSocketImpl() |
|
Protected methods |
|
|---|---|
abstract void |
bind(int lport, InetAddress laddr) 将数据报套接字绑定到本地端口和地址。 |
abstract void |
close() 关闭插座。 |
void |
connect(InetAddress address, int port) 将数据报套接字连接到远程目标。 |
abstract void |
create() 创建一个数据报套接字。 |
void |
disconnect() 从远程目标断开数据报套接字。 |
FileDescriptor |
getFileDescriptor() 获取数据报套接字文件描述符。 |
int |
getLocalPort() 获取本地端口。 |
abstract byte |
getTTL() 此方法在API级别1中已弃用。请改用getTimeToLive。 |
abstract int |
getTimeToLive() 检索TTL(生存时间)选项。 |
abstract void |
join(InetAddress inetaddr) 加入多播组。 |
abstract void |
joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) 加入多播组。 |
abstract void |
leave(InetAddress inetaddr) 离开多播组。 |
abstract void |
leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) 离开多播组。 |
abstract int |
peek(InetAddress i) 偷看数据包以查看其来源。 |
abstract int |
peekData(DatagramPacket p) 偷看数据包以查看其来源。 |
abstract void |
receive(DatagramPacket p) 接收数据报包。 |
abstract void |
send(DatagramPacket p) 发送数据报包。 |
abstract void |
setTTL(byte ttl) 此方法在API级别1中已弃用。请改用setTimeToLive。 |
abstract void |
setTimeToLive(int ttl) 设置TTL(生存时间)选项。 |
Inherited methods |
|
|---|---|
java.lang.Object
|
|
java.net.SocketOptions
|
|
void bind (int lport,
InetAddress laddr)
将数据报套接字绑定到本地端口和地址。
| Parameters | |
|---|---|
lport |
int: the local port |
laddr |
InetAddress: the local address |
| Throws | |
|---|---|
SocketException |
if there is an error in the underlying protocol, such as a TCP error. |
void connect (InetAddress address, int port)
将数据报套接字连接到远程目标。 这将远程地址与本地套接字相关联,以便数据报只能发送到此目的地并从此目的地接收。 这可能会被重写以调用本地系统连接。
如果套接字所连接的远程目标不存在或者无法访问,并且如果该地址收到ICMP目标不可达数据包,则后续对发送或接收的调用可能会引发PortUnreachableException。 请注意,不能保证会抛出异常。
| Parameters | |
|---|---|
address |
InetAddress: the remote InetAddress to connect to |
port |
int: the remote port number |
| Throws | |
|---|---|
SocketException |
may be thrown if the socket cannot be connected to the remote destination |
void create ()
创建一个数据报套接字。
| Throws | |
|---|---|
SocketException |
if there is an error in the underlying protocol, such as a TCP error. |
FileDescriptor getFileDescriptor ()
获取数据报套接字文件描述符。
| Returns | |
|---|---|
FileDescriptor |
a FileDescriptor object representing the datagram socket file descriptor |
int getLocalPort ()
获取本地端口。
| Returns | |
|---|---|
int |
an int representing the local port value |
byte getTTL ()
此方法在API级别1中已弃用。
改用getTimeToLive。
检索TTL(生存时间)选项。
| Returns | |
|---|---|
byte |
a byte representing the TTL value |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while retrieving the time-to-live option |
也可以看看:
int getTimeToLive ()
检索TTL(生存时间)选项。
| Returns | |
|---|---|
int |
an int representing the time-to-live value |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while retrieving the time-to-live option |
也可以看看:
void join (InetAddress inetaddr)
加入多播组。
| Parameters | |
|---|---|
inetaddr |
InetAddress: multicast address to join. |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while joining the multicast group. |
void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
加入多播组。
| Parameters | |
|---|---|
mcastaddr |
SocketAddress: address to join. |
netIf |
NetworkInterface: specifies the local interface to receive multicast datagram packets |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while joining the multicast group |
void leave (InetAddress inetaddr)
离开多播组。
| Parameters | |
|---|---|
inetaddr |
InetAddress: multicast address to leave. |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while leaving the multicast group. |
void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
离开多播组。
| Parameters | |
|---|---|
mcastaddr |
SocketAddress: address to leave. |
netIf |
NetworkInterface: specified the local interface to leave the group at |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while leaving the multicast group |
int peek (InetAddress i)
偷看数据包以查看其来源。 将指定的InetAddress更新为数据包来自的地址。
| Parameters | |
|---|---|
i |
InetAddress: an InetAddress object |
| Returns | |
|---|---|
int |
the port number which the packet came from. |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs |
PortUnreachableException |
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
int peekData (DatagramPacket p)
偷看数据包以查看其来源。 数据被复制到指定的DatagramPacket 。 数据被返回,但没有被使用,所以后面的peekData / receive操作将看到相同的数据。
| Parameters | |
|---|---|
p |
DatagramPacket: the Packet Received. |
| Returns | |
|---|---|
int |
the port number which the packet came from. |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs |
PortUnreachableException |
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
void receive (DatagramPacket p)
接收数据报包。
| Parameters | |
|---|---|
p |
DatagramPacket: the Packet Received. |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while receiving the datagram packet. |
PortUnreachableException |
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
void send (DatagramPacket p)
发送数据报包。 数据包包含数据和发送数据包的目标地址。
| Parameters | |
|---|---|
p |
DatagramPacket: the packet to be sent. |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while sending the datagram packet. |
PortUnreachableException |
may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
void setTTL (byte ttl)
此方法在API级别1中已弃用。
改用setTimeToLive。
设置TTL(生存时间)选项。
| Parameters | |
|---|---|
ttl |
byte: a byte specifying the TTL value |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while setting the time-to-live option. |
也可以看看:
void setTimeToLive (int ttl)
设置TTL(生存时间)选项。
| Parameters | |
|---|---|
ttl |
int: an int specifying the time-to-live value |
| Throws | |
|---|---|
IOException |
if an I/O exception occurs while setting the time-to-live option. |
也可以看看: