鴻蒙OS DatagramSocketImpl

2022-06-07 17:44 更新

DatagramSocketImpl

java.lang.Object

|---java.net.DatagramSocketImpl

  1. public abstract class DatagramSocketImpl
  2. extends Object
  3. implements SocketOptions

抽象數(shù)據(jù)報(bào)和多播套接字實(shí)現(xiàn)基類。

字段摘要

修飾符和類型 方法 描述
protected FileDescriptor fd 文件描述符對(duì)象。
protected int localPort 本地端口號(hào)。
從接口 java.net.SocketOptions 繼承的字段
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

構(gòu)造函數(shù)摘要

構(gòu)造函數(shù) 描述
DatagramSocketImpl()

方法總結(jié)

修飾符和類型 方法 描述
protected abstract void bind(int lport, InetAddress laddr) 將數(shù)據(jù)報(bào)套接字綁定到本地端口和地址。
protected abstract void close() 關(guān)閉插座。
protected void connect(InetAddress address, int port) 將數(shù)據(jù)報(bào)套接字連接到遠(yuǎn)程目標(biāo)。
protected abstract void create() 創(chuàng)建一個(gè)數(shù)據(jù)報(bào)套接字。
protected void disconnect() 斷開數(shù)據(jù)報(bào)套接字與其遠(yuǎn)程目標(biāo)的連接。
protected FileDescriptor getFileDescriptor() 獲取數(shù)據(jù)報(bào)套接字文件描述符。
protected int getLocalPort() 獲取本地端口。
protected abstract int getTimeToLive() 檢索 TTL(time-to-live)選項(xiàng)。
protected abstract byte getTTL() 已棄用。 改用 getTimeToLive。
protected abstract void join(InetAddress inetaddr) 加入多播組。
protected abstract void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) 加入多播組。
protected abstract void leave(InetAddress inetaddr) 離開多播組。
protected abstract void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) 離開多播組。
protected abstract int peek(InetAddress i) 偷看包裹,看看它來自誰。
protected abstract int peekData(DatagramPacket p) 偷看包裹,看看它來自誰。
protected abstract void receive(DatagramPacket p) 接收數(shù)據(jù)報(bào)包。
protected abstract void send(DatagramPacket p) 發(fā)送一個(gè)數(shù)據(jù)報(bào)包。
protected abstract void setTimeToLive(int ttl) 設(shè)置 TTL(time-to-live)選項(xiàng)。
protected abstract void setTTL(byte ttl) 已棄用。 改用 setTimeToLive。
從類 java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
從接口 java.net.SocketOptions 繼承的方法
getOption, setOption

字段詳細(xì)信息

fd

protected FileDescriptor fd

文件描述符對(duì)象。

localPort

protected int localPort

本地端口號(hào)。

構(gòu)造函數(shù)詳細(xì)信息

DatagramSocketImpl

public DatagramSocketImpl()

方法詳情

create

protected abstract void create() throws SocketException

創(chuàng)建一個(gè)數(shù)據(jù)報(bào)套接字。

Throws:

Throw名稱 Throw描述
SocketException 如果底層協(xié)議有錯(cuò)誤,例如 TCP 錯(cuò)誤。

bind

protected abstract void bind(int lport, InetAddress laddr) throws SocketException

將數(shù)據(jù)報(bào)套接字綁定到本地端口和地址。

參數(shù):

參數(shù)名稱 參數(shù)描述
lport 本地端口
laddr 本地地址

Throws:

Throw名稱 Throw描述
SocketException 如果底層協(xié)議有錯(cuò)誤,例如 TCP 錯(cuò)誤。

send

protected abstract void send(DatagramPacket p) throws IOException

發(fā)送一個(gè)數(shù)據(jù)報(bào)包。 數(shù)據(jù)包包含數(shù)據(jù)和要將數(shù)據(jù)包發(fā)送到的目標(biāo)地址。

參數(shù):

參數(shù)名稱 參數(shù)描述
p 要發(fā)送的數(shù)據(jù)包。

Throws:

Throw名稱 Throw描述
IOException 如果在發(fā)送數(shù)據(jù)報(bào)包時(shí)發(fā)生 I/O 異常。
PortUnreachableException 如果套接字連接到當(dāng)前無法到達(dá)的目的地,則可能會(huì)拋出。 請(qǐng)注意,不能保證會(huì)引發(fā)異常。

connect

protected void connect(InetAddress address, int port) throws SocketException

將數(shù)據(jù)報(bào)套接字連接到遠(yuǎn)程目標(biāo)。 這將遠(yuǎn)程地址與本地套接字相關(guān)聯(lián),以便數(shù)據(jù)報(bào)只能發(fā)送到該目的地并從該目的地接收。 這可能會(huì)被覆蓋以調(diào)用本機(jī)系統(tǒng)連接。

如果套接字連接到的遠(yuǎn)程目標(biāo)不存在,或者無法到達(dá),并且如果已接收到該地址的 ICMP 目標(biāo)無法到達(dá)數(shù)據(jù)包,則后續(xù)調(diào)用 send 或 receive 可能會(huì)拋出 PortUnreachableException。 請(qǐng)注意,不能保證會(huì)引發(fā)異常。

參數(shù):

參數(shù)名稱 參數(shù)描述
address 要連接的遠(yuǎn)程 InetAddress
port 遠(yuǎn)程端口號(hào)

Throws:

Throw名稱 Throw Description
SocketException 如果套接字無法連接到遠(yuǎn)程目標(biāo),可能會(huì)拋出

disconnect

protected void disconnect()

斷開數(shù)據(jù)報(bào)套接字與其遠(yuǎn)程目標(biāo)的連接。

peek

protected abstract int peek(InetAddress i) throws IOException

偷看包裹,看看它來自誰。 將指定的 InetAddress 更新為數(shù)據(jù)包的來源地址。

參數(shù):

參數(shù)名稱 參數(shù)描述
i 一個(gè) InetAddress 對(duì)象

返回:

數(shù)據(jù)包來自的端口號(hào)。

Throws:

Throw名稱 Throw描述
IOException 如果發(fā)生 I/O 異常
PortUnreachableException 如果套接字連接到當(dāng)前無法到達(dá)的目的地,則可能會(huì)拋出。 請(qǐng)注意,不能保證會(huì)引發(fā)異常。

peekData

protected abstract int peekData(DatagramPacket p) throws IOException

偷看包裹,看看它來自誰。 數(shù)據(jù)被復(fù)制到指定的 DatagramPacket 中。 數(shù)據(jù)被返回,但不被消費(fèi),因此后續(xù)的 peekData/receive 操作將看到相同的數(shù)據(jù)。

參數(shù):

參數(shù)名稱 參數(shù)描述
p 收到的數(shù)據(jù)包。

返回:

數(shù)據(jù)包來自的端口號(hào)。

Throws:

Throw名稱 Throw描述
IOException 如果發(fā)生 I/O 異常
PortUnreachableException 如果套接字連接到當(dāng)前無法到達(dá)的目的地,則可能會(huì)拋出。 請(qǐng)注意,不能保證會(huì)引發(fā)異常。

receive

protected abstract void receive(DatagramPacket p) throws IOException

接收數(shù)據(jù)報(bào)包。

參數(shù):

參數(shù)名稱 參數(shù)描述
p 收到的數(shù)據(jù)包。

Throws:

Throw名稱 Throw描述
IOException 如果在接收數(shù)據(jù)報(bào)包時(shí)發(fā)生 I/O 異常。
PortUnreachableException 如果套接字連接到當(dāng)前無法到達(dá)的目的地,則可能會(huì)拋出。 請(qǐng)注意,不能保證會(huì)引發(fā)異常。

setTTL

@Deprecated protected abstract void setTTL(byte ttl) throws IOException

已棄用。 改用 setTimeToLive。

設(shè)置 TTL (time-to-live) 選項(xiàng)。

參數(shù):

參數(shù)名稱 參數(shù)描述
ttl 指定 TTL 值的字節(jié)

Throws:

Throw名稱 Throw描述
IOException 如果在設(shè)置生存時(shí)間選項(xiàng)時(shí)發(fā)生 I/O 異常。

getTTL

@Deprecated protected abstract byte getTTL() throws IOException

已棄用。 改用 getTimeToLive。

檢索 TTL (time-to-live) 選項(xiàng)。

返回:

表示 TTL 值的字節(jié)

Throws:

Throw名稱 Throw描述
IOException 如果在檢索生存時(shí)間選項(xiàng)時(shí)發(fā)生 I/O 異常

setTimeToLive

protected abstract void setTimeToLive(int ttl) throws IOException

設(shè)置 TTL (time-to-live) 選項(xiàng)。

參數(shù):

參數(shù)名稱 參數(shù)描述
ttl 指定 time-to-live 值的 int

Throws:

Throw名稱 Throw描述
IOException 如果在設(shè)置 time-to-live 選項(xiàng)時(shí)發(fā)生 I/O 異常。

getTimeToLive

protected abstract int getTimeToLive() throws IOException

檢索 TTL (time-to-live) 選項(xiàng)。

返回:

表示生存時(shí)間值的 int

Throws:

Throw名稱 Throw描述
IOException 如果在檢索生存時(shí)間選項(xiàng)時(shí)發(fā)生 I/O 異常

join

protected abstract void join(InetAddress inetaddr) throws IOException

加入多播組。

參數(shù):

參數(shù)名稱 參數(shù)描述
inetaddr 多播地址加入。

Throws:

Throw名稱 Throw描述
IOException 如果加入多播組時(shí)發(fā)生 I/O 異常。

leave

protected abstract void leave(InetAddress inetaddr) throws IOException

離開多播組。

參數(shù):

參數(shù)名稱 參數(shù)描述
inetaddr 離開的多播地址。

Throws:

Throw名稱 Throw描述
IOException 如果在離開多播組時(shí)發(fā)生 I/O 異常。

joinGroup

protected abstract void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

加入多播組。

參數(shù):

參數(shù)名稱 參數(shù)描述
mcastaddr 加入地址。
netIf 指定接收多播數(shù)據(jù)報(bào)包的本地接口

Throws:

Throw名稱 Throw描述
IOException 如果加入多播組時(shí)發(fā)生 I/O 異常

leaveGroup

protected abstract void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException

離開多播組。

參數(shù):

參數(shù)名稱 參數(shù)描述
mcastaddr 離開的地址。
netIf 指定離開組的本地接口

Throws:

Throw名稱 Throw描述
IOException 如果在離開多播組時(shí)發(fā)生 I/O 異常

close

protected abstract void close()

關(guān)閉套接字。

getLocalPort

protected int getLocalPort()

獲取本地端口。

返回:

表示本地端口值的 int

getFileDescriptor

protected FileDescriptor getFileDescriptor()

獲取數(shù)據(jù)報(bào)套接字文件描述符。

返回:

表示數(shù)據(jù)報(bào)套接字文件描述符的 FileDescriptor 對(duì)象

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)