Most visited

Recently visited

Added in API level 1

DatagramSocketImpl

public abstract class DatagramSocketImpl
extends Object implements SocketOptions

java.lang.Object
   ↳ java.net.DatagramSocketImpl


抽象数据报和多播套接字实现基类。

Summary

Inherited constants

From interface 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

From class java.lang.Object
From interface java.net.SocketOptions

Fields

fd

Added in API level 1
FileDescriptor fd

文件描述符对象。

localPort

Added in API level 1
int localPort

本地端口号。

Public constructors

DatagramSocketImpl

Added in API level 1
DatagramSocketImpl ()

Protected methods

bind

Added in API level 1
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.

close

Added in API level 1
void close ()

关闭插座。

connect

Added in API level 1
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

create

Added in API level 1
void create ()

创建一个数据报套接字。

Throws
SocketException if there is an error in the underlying protocol, such as a TCP error.

disconnect

Added in API level 1
void disconnect ()

从远程目标断开数据报套接字。

getFileDescriptor

Added in API level 1
FileDescriptor getFileDescriptor ()

获取数据报套接字文件描述符。

Returns
FileDescriptor a FileDescriptor object representing the datagram socket file descriptor

getLocalPort

Added in API level 1
int getLocalPort ()

获取本地端口。

Returns
int an int representing the local port value

getTTL

Added in API level 1
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

也可以看看:

getTimeToLive

Added in API level 1
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

也可以看看:

join

Added in API level 1
void join (InetAddress inetaddr)

加入多播组。

Parameters
inetaddr InetAddress: multicast address to join.
Throws
IOException if an I/O exception occurs while joining the multicast group.

joinGroup

Added in API level 1
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

leave

Added in API level 1
void leave (InetAddress inetaddr)

离开多播组。

Parameters
inetaddr InetAddress: multicast address to leave.
Throws
IOException if an I/O exception occurs while leaving the multicast group.

leaveGroup

Added in API level 1
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

peek

Added in API level 1
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.

peekData

Added in API level 1
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.

receive

Added in API level 1
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.

send

Added in API level 1
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.

setTTL

Added in API level 1
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.

也可以看看:

setTimeToLive

Added in API level 1
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.

也可以看看:

Hooray!