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

!4528 翻译已完成4160

Merge pull request !4528 from shawn_he/4160-a
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## Modules to Import ## Modules to Import
```js ```
import socket from '@ohos.net.socket'; import socket from '@ohos.net.socket';
``` ```
...@@ -28,7 +28,7 @@ Creates a **UDPSocket** object. ...@@ -28,7 +28,7 @@ Creates a **UDPSocket** object.
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
``` ```
...@@ -56,7 +56,7 @@ Binds the IP address and port number. The port number can be specified or random ...@@ -56,7 +56,7 @@ Binds the IP address and port number. The port number can be specified or random
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
if (err) { if (err) {
...@@ -93,7 +93,7 @@ Binds the IP address and port number. The port number can be specified or random ...@@ -93,7 +93,7 @@ Binds the IP address and port number. The port number can be specified or random
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.bind({address: '192.168.xx.xxx', port: 8080, family: 1}); let promise = udp.bind({address: '192.168.xx.xxx', port: 8080, family: 1});
promise .then(() => { promise .then(() => {
...@@ -110,6 +110,8 @@ send\(options: UDPSendOptions, callback: AsyncCallback<void\>\): void ...@@ -110,6 +110,8 @@ send\(options: UDPSendOptions, callback: AsyncCallback<void\>\): void
Sends data over a UDPSocket connection. This API uses an asynchronous callback to return the result. Sends data over a UDPSocket connection. This API uses an asynchronous callback to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
**Required permission**: ohos.permission.INTERNET **Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -123,7 +125,7 @@ Sends data over a UDPSocket connection. This API uses an asynchronous callback t ...@@ -123,7 +125,7 @@ Sends data over a UDPSocket connection. This API uses an asynchronous callback t
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.send({ udp.send({
data:'Hello, server!', data:'Hello, server!',
...@@ -148,6 +150,8 @@ send\(options: UDPSendOptions\): Promise<void\> ...@@ -148,6 +150,8 @@ send\(options: UDPSendOptions\): Promise<void\>
Sends data over a UDPSocket connection. This API uses a promise to return the result. Sends data over a UDPSocket connection. This API uses a promise to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
**Required permission**: ohos.permission.INTERNET **Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -166,7 +170,7 @@ Sends data over a UDPSocket connection. This API uses a promise to return the re ...@@ -166,7 +170,7 @@ Sends data over a UDPSocket connection. This API uses a promise to return the re
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.send({ let promise = udp.send({
data:'Hello, server!', data:'Hello, server!',
...@@ -202,7 +206,7 @@ Closes a UDPSocket connection. This API uses an asynchronous callback to return ...@@ -202,7 +206,7 @@ Closes a UDPSocket connection. This API uses an asynchronous callback to return
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.close(err => { udp.close(err => {
if (err) { if (err) {
...@@ -232,7 +236,7 @@ Closes a UDPSocket connection. This API uses a promise to return the result. ...@@ -232,7 +236,7 @@ Closes a UDPSocket connection. This API uses a promise to return the result.
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.close(); let promise = udp.close();
promise.then(() => { promise.then(() => {
...@@ -264,7 +268,7 @@ Obtains the status of the UDPSocket connection. This API uses an asynchronous ca ...@@ -264,7 +268,7 @@ Obtains the status of the UDPSocket connection. This API uses an asynchronous ca
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
if (err) { if (err) {
...@@ -304,7 +308,7 @@ Obtains the status of the UDPSocket connection. This API uses a promise to retur ...@@ -304,7 +308,7 @@ Obtains the status of the UDPSocket connection. This API uses a promise to retur
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
if (err) { if (err) {
...@@ -345,7 +349,7 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous ...@@ -345,7 +349,7 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1}, err=> { udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1}, err=> {
if (err) { if (err) {
...@@ -397,7 +401,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re ...@@ -397,7 +401,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let promise = udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1}); let promise = udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1});
promise.then(() => { promise.then(() => {
...@@ -437,7 +441,7 @@ Enables listening for message receiving events of the UDPSocket connection. This ...@@ -437,7 +441,7 @@ Enables listening for message receiving events of the UDPSocket connection. This
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.on('message', value => { udp.on('message', value => {
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
...@@ -465,7 +469,7 @@ Disables listening for message receiving events of the UDPSocket connection. Thi ...@@ -465,7 +469,7 @@ Disables listening for message receiving events of the UDPSocket connection. Thi
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let callback = value =>{ let callback = value =>{
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
...@@ -494,7 +498,7 @@ Enables listening for data packet message events or close events of the UDPSocke ...@@ -494,7 +498,7 @@ Enables listening for data packet message events or close events of the UDPSocke
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.on('listening', () => { udp.on('listening', () => {
console.log("on listening success"); console.log("on listening success");
...@@ -525,7 +529,7 @@ Disables listening for data packet message events or close events of the UDPSock ...@@ -525,7 +529,7 @@ Disables listening for data packet message events or close events of the UDPSock
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let callback1 = () =>{ let callback1 = () =>{
console.log("on listening, success"); console.log("on listening, success");
...@@ -562,7 +566,7 @@ Enables listening for error events of the UDPSocket connection. This API uses an ...@@ -562,7 +566,7 @@ Enables listening for error events of the UDPSocket connection. This API uses an
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
udp.on('error', err => { udp.on('error', err => {
console.log("on error, err:" + JSON.stringify(err)) console.log("on error, err:" + JSON.stringify(err))
...@@ -590,7 +594,7 @@ Disables listening for error events of the UDPSocket connection. This API uses a ...@@ -590,7 +594,7 @@ Disables listening for error events of the UDPSocket connection. This API uses a
**Example** **Example**
```js ```
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let callback = err =>{ let callback = err =>{
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
...@@ -622,7 +626,7 @@ Defines the parameters for sending data over the UDPSocket connection. ...@@ -622,7 +626,7 @@ Defines the parameters for sending data over the UDPSocket connection.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ---------------------------------- | ---- | -------------- | | ------- | ---------------------------------- | ---- | -------------- |
| data | string \| ArrayBuffer<sup>8+</sup> | Yes | Data to send. | | data | string | Yes | Data to send. |
| address | [NetAddress](#netaddress) | Yes | Destination address.| | address | [NetAddress](#netaddress) | Yes | Destination address.|
## UDPExtraOptions ## UDPExtraOptions
...@@ -680,7 +684,7 @@ Creates a **TCPSocket** object. ...@@ -680,7 +684,7 @@ Creates a **TCPSocket** object.
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
``` ```
...@@ -709,7 +713,7 @@ Binds the IP address and port number. The port number can be specified or random ...@@ -709,7 +713,7 @@ Binds the IP address and port number. The port number can be specified or random
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
if (err) { if (err) {
...@@ -745,7 +749,7 @@ Binds the IP address and port number. The port number can be specified or random ...@@ -745,7 +749,7 @@ Binds the IP address and port number. The port number can be specified or random
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); let promise = tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1});
promise.then(() => { promise.then(() => {
...@@ -775,7 +779,7 @@ Sets up a connection to the specified IP address and port number. This API uses ...@@ -775,7 +779,7 @@ Sets up a connection to the specified IP address and port number. This API uses
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}, err => { tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}, err => {
if (err) { if (err) {
...@@ -811,7 +815,7 @@ Sets up a connection to the specified IP address and port number. This API uses ...@@ -811,7 +815,7 @@ Sets up a connection to the specified IP address and port number. This API uses
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -844,7 +848,7 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t ...@@ -844,7 +848,7 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -891,7 +895,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re ...@@ -891,7 +895,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise1 = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise1 = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise1.then(() => { promise1.then(() => {
...@@ -929,7 +933,7 @@ Closes a TCPSocket connection. This API uses an asynchronous callback to return ...@@ -929,7 +933,7 @@ Closes a TCPSocket connection. This API uses an asynchronous callback to return
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.close(err => { tcp.close(err => {
if (err) { if (err) {
...@@ -959,7 +963,7 @@ Closes a TCPSocket connection. This API uses a promise to return the result. ...@@ -959,7 +963,7 @@ Closes a TCPSocket connection. This API uses a promise to return the result.
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.close(); let promise = tcp.close();
promise.then(() => { promise.then(() => {
...@@ -991,7 +995,7 @@ Obtains the remote address of a TCPSocket connection. This API uses an asynchron ...@@ -991,7 +995,7 @@ Obtains the remote address of a TCPSocket connection. This API uses an asynchron
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -1030,7 +1034,7 @@ Obtains the remote address of a TCPSocket connection. This API uses a promise to ...@@ -1030,7 +1034,7 @@ Obtains the remote address of a TCPSocket connection. This API uses a promise to
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise1 = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise1 = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise1.then(() => { promise1.then(() => {
...@@ -1069,7 +1073,7 @@ Obtains the status of the TCPSocket connection. This API uses an asynchronous ca ...@@ -1069,7 +1073,7 @@ Obtains the status of the TCPSocket connection. This API uses an asynchronous ca
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -1109,7 +1113,7 @@ Obtains the status of the TCPSocket connection. This API uses a promise to retur ...@@ -1109,7 +1113,7 @@ Obtains the status of the TCPSocket connection. This API uses a promise to retur
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -1148,7 +1152,7 @@ Sets other properties of the TCPSocket connection. This API uses an asynchronous ...@@ -1148,7 +1152,7 @@ Sets other properties of the TCPSocket connection. This API uses an asynchronous
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -1203,7 +1207,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re ...@@ -1203,7 +1207,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000}); let promise = tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , timeout: 6000});
promise.then(() => { promise.then(() => {
...@@ -1246,7 +1250,7 @@ Enables listening for message receiving events of the TCPSocket connection. This ...@@ -1246,7 +1250,7 @@ Enables listening for message receiving events of the TCPSocket connection. This
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.on('message', value => { tcp.on('message', value => {
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo) console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo)
...@@ -1274,7 +1278,7 @@ Disables listening for message receiving events of the TCPSocket connection. Thi ...@@ -1274,7 +1278,7 @@ Disables listening for message receiving events of the TCPSocket connection. Thi
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let callback = value =>{ let callback = value =>{
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
...@@ -1304,7 +1308,7 @@ Enables listening for connection or close events of the TCPSocket connection. Th ...@@ -1304,7 +1308,7 @@ Enables listening for connection or close events of the TCPSocket connection. Th
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.on('connect', () => { tcp.on('connect', () => {
console.log("on connect success") console.log("on connect success")
...@@ -1335,7 +1339,7 @@ Disables listening for connection or close events of the TCPSocket connection. T ...@@ -1335,7 +1339,7 @@ Disables listening for connection or close events of the TCPSocket connection. T
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let callback1 = () =>{ let callback1 = () =>{
console.log("on connect success"); console.log("on connect success");
...@@ -1371,7 +1375,7 @@ Enables listening for error events of the TCPSocket connection. This API uses an ...@@ -1371,7 +1375,7 @@ Enables listening for error events of the TCPSocket connection. This API uses an
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
tcp.on('error', err => { tcp.on('error', err => {
console.log("on error, err:" + JSON.stringify(err)) console.log("on error, err:" + JSON.stringify(err))
...@@ -1399,7 +1403,7 @@ Disables listening for error events of the TCPSocket connection. This API uses a ...@@ -1399,7 +1403,7 @@ Disables listening for error events of the TCPSocket connection. This API uses a
**Example** **Example**
```js ```
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let callback = err =>{ let callback = err =>{
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
...@@ -1430,7 +1434,7 @@ Defines the parameters for sending data over the TCPSocket connection. ...@@ -1430,7 +1434,7 @@ Defines the parameters for sending data over the TCPSocket connection.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| data | string\| ArrayBuffer<sup>8+</sup> | Yes | Data to send. | | data | string | Yes | Data to send. |
| encoding | string | No | Character encoding format. The options are as follows: **UTF-8**, **UTF-16BE**, **UTF-16LE**, **UTF-16**, **US-AECII**, and **ISO-8859-1**. The default value is **UTF-8**.| | encoding | string | No | Character encoding format. The options are as follows: **UTF-8**, **UTF-16BE**, **UTF-16LE**, **UTF-16**, **US-AECII**, and **ISO-8859-1**. The default value is **UTF-8**.|
## TCPExtraOptions ## TCPExtraOptions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册