提交 b4c3e59c 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 9c9d5ec7
......@@ -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&lt;void&gt;): 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&lt;void&gt; | 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&lt;void&gt;
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&lt;void&gt; | 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.
先完成此消息的编辑!
想要评论请 注册