未验证 提交 b933ad0c 编写于 作者: O openharmony_ci 提交者: Gitee

!2804 翻译已完成2624#I4ZW5Y

Merge pull request !2804 from shawn_he/b2624
......@@ -684,83 +684,14 @@ Before invoking NetHandle APIs, call **getNetHandle** to obtain a **NetHandle**
| ------ | ------ | ------------------------- |
| netId | number | Network ID. The value must be greater than or equal to 100.|
### bindSocket
bindSocket(socketParam: TCPSocket | UDPSocket, callback: AsyncCallback<void>): void
Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------- | ---- | ---------------- |
| socketParam | TCPSocket \| UDPSocket | Yes | **TCPSocket** or **UDPSocket** object.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. |
**Example**
```
// Bind the TCPSocket object.
connection.getDefaultNet().then(function (netHandle) {
let tcpSocket = socket.constructTCPSocketInstance()
netHandle.bindSocket(tcpSocket, (function (error) {
console.log(JSON.stringify(error))
}))
})
// Bind the UDPSocket object.
connection.getDefaultNet().then(function (netHandle) {
let udpSocket = socket.constructUDPSocketInstance()
netHandle.bindSocket(udpSocket, (function (error) {
console.log(JSON.stringify(error))
}))
})
```
### bindSocket
bindSocket(socketParam: TCPSocket | UDPSocket): Promise<void>
Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| socketParam | TCPSocket \| UDPSocket | Yes | **TCPSocket** or **UDPSocket** object.|
**Return Value**
| Type | Description |
| ------------------- | --------------------------- |
| Promise<void> | Promise used to return the result.|
**Example**
```
// Bind the TCPSocket object.
connection.getDefaultNet().then(function (netHandle) {
let tcpSocket = socket.constructTCPSocketInstance()
netHandle.bindSocket(tcpSocket).then(function () {
console.log("bind socket success")
})
})
// Bind the UDPSocket object.
connection.getDefaultNet().then(function (netHandle) {
let udpSocket = socket.constructUDPSocketInstance()
netHandle.bindSocket(udpSocket).then(function () {
console.log("bind socket success")
})
})
```
### getAddressesByName
getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void
Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
......@@ -788,6 +719,8 @@ getAddressesByName(host: string): Promise\<Array\<NetAddress>>
Resolves the host name by using the corresponding network to obtain all IP addresses. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
......@@ -819,6 +752,8 @@ getAddressByName(host: string, callback: AsyncCallback\<NetAddress>): void
Resolves the host name by using the corresponding network to obtain the first IP address. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
......@@ -846,6 +781,8 @@ getAddressByName(host: string): Promise\<NetAddress>
Resolves the host name by using the corresponding network to obtain the first IP address. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
......@@ -971,4 +908,4 @@ Defines the network address.
| ------- | ------ | ------------------------------ |
| address | string | Network address. |
| family | number | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.|
| port | number | Port number. The value ranges from **0** to **65535**. |
| port | number | Port number. The value ranges from **0** to **65535**. |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册