@@ -44,9 +44,9 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
...
@@ -44,9 +44,9 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
**Using Native APIs**
**Using Native APIs**
1. Define the IPC interface **ITestAbility**.
1. Define the IPC interface **ITestAbility**.
**ITestAbility** inherits the IPC base class **IRemoteBroker** and defines descriptors, functions, and message code. The functions need to be implemented on both the proxy and stub.
**ITestAbility** inherits the IPC base class **IRemoteBroker** and defines descriptors, functions, and message code. The functions need to be implemented on both the proxy and stub.
```
```
class ITestAbility : public IRemoteBroker {
class ITestAbility : public IRemoteBroker {
...
@@ -58,9 +58,9 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
...
@@ -58,9 +58,9 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
};
};
```
```
2. Define and implement service provider **TestAbilityStub**.
2. Define and implement service provider **TestAbilityStub**.
This class is related to the IPC framework and needs to inherit **IRemoteStub<ITestAbility\>**. You need to override **OnRemoteRequest** on the stub to receive requests from the proxy.
This class is related to the IPC framework and needs to inherit **IRemoteStub<ITestAbility\>**. You need to override **OnRemoteRequest** on the stub to receive requests from the proxy.
```
```
class TestAbilityStub : public IRemoteStub<ITestAbility> {
class TestAbilityStub : public IRemoteStub<ITestAbility> {
...
@@ -85,7 +85,7 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
...
@@ -85,7 +85,7 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
}
}
```
```
3. Define the **TestAbility** class that implements functions for the stub.
3. Define the **TestAbility** class that implements functions for the stub.
```
```
class TestAbility : public TestAbilityStub {
class TestAbility : public TestAbilityStub {
...
@@ -98,9 +98,9 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
...
@@ -98,9 +98,9 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
}
}
```
```
4. Define and implement **TestAbilityProxy**.
4. Define and implement **TestAbilityProxy**.
This class is implemented on the proxy and inherits **IRemoteProxy<ITestAbility\>**. You can call **SendRequest** to send a request to the stub and expose the capabilities provided by the stub.
This class is implemented on the proxy and inherits **IRemoteProxy<ITestAbility\>**. You can call **SendRequest** to send a request to the stub and expose the capabilities provided by the stub.
```
```
class TestAbilityProxy : public IRemoteProxy<ITestAbility> {
class TestAbilityProxy : public IRemoteProxy<ITestAbility> {
...
@@ -128,7 +128,7 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
...
@@ -128,7 +128,7 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
5. Register and start an SA.
5. Register and start an SA.
Call **AddSystemAbility** to register the **TestAbilityStub** instance of the SA with **SystemAbilityManager**. The registration parameters vary depending on whether the **SystemAbilityManager** resides on the same device as the SA.
Call **AddSystemAbility** to register the **TestAbilityStub** instance of the SA with **SystemAbilityManager**. The registration parameters vary depending on whether the **SystemAbilityManager** resides on the same device as the SA.
```
```
// Register the TestAbilityStub instance with the SystemAbilityManager on the same device as the SA.
// Register the TestAbilityStub instance with the SystemAbilityManager on the same device as the SA.
...
@@ -144,7 +144,7 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
...
@@ -144,7 +144,7 @@ IPC/RPC enables a proxy and a stub that run on different processes to communicat
6. Obtain the SA.
6. Obtain the SA.
Call the **GetSystemAbility** function of the **SystemAbilityManager** class to obtain the **IRemoteObject** for the SA, and create a **TestAbilityProxy** instance.
Call the **GetSystemAbility** function of the **SystemAbilityManager** class to obtain the **IRemoteObject** for the SA, and create a **TestAbilityProxy** instance.
```
```
// Obtain the proxy of the SA registered on the local device.
// Obtain the proxy of the SA registered on the local device.
@@ -10,26 +10,26 @@ Your application can transmit data through Socket connections. Currently, the TC
...
@@ -10,26 +10,26 @@ Your application can transmit data through Socket connections. Currently, the TC
The Socket connection function is mainly implemented by the Socket module. The following table describes the related APIs.
The Socket connection function is mainly implemented by the Socket module. The following table describes the related APIs.
| API| Description|
| API| Description|
| -------- | -------- |
| -------- | -------- |
| constructUDPSocketInstance() | Creates a **UDPSocket** object.|
| constructUDPSocketInstance() | Creates a **UDPSocket** object.|
| constructTCPSocketInstance() | Creates a **TCPSocket** object.|
| constructTCPSocketInstance() | Creates a **TCPSocket** object.|
| bind() | Binds the IP address and port number.|
| bind() | Binds the IP address and port number.|
| send() | Sends data.|
| send() | Sends data.|
| close() | Closes a Socket connection.|
| close() | Closes a Socket connection.|
| getState() | Obtains the Socket connection status.|
| getState() | Obtains the Socket connection status.|
| connect() | Connects to the specified IP address and port. This function is supported only for TCP.|
| connect() | Connects to the specified IP address and port. This function is supported only for TCP.|
| getRemoteAddress() | Obtains the peer address of the Socket connection. This function is supported only for TCP. The **connect** API must have been called before you use this API.|
| getRemoteAddress() | Obtains the peer address of the Socket connection. This function is supported only for TCP. The **connect** API must have been called before you use this API.|
| on(type: 'message') | Enables listening for **message** events of the Socket connection.|
| on(type: 'message') | Enables listening for **message** events of the Socket connection.|
| off(type: 'message') | Disables listening for **message** events of the Socket connection.|
| off(type: 'message') | Disables listening for **message** events of the Socket connection.|
| on(type: 'close') | Enables listening for **close** events of the Socket connection.|
| on(type: 'close') | Enables listening for **close** events of the Socket connection.|
| off(type: 'close') | Disables listening for **close** events of the Socket connection.|
| off(type: 'close') | Disables listening for **close** events of the Socket connection.|
| on(type: 'error') | Enables listening for **error** events of the Socket connection.|
| on(type: 'error') | Enables listening for **error** events of the Socket connection.|
| off(type: 'error') | Disables listening for **error** events of the Socket connection.|
| off(type: 'error') | Disables listening for **error** events of the Socket connection.|
| on(type: 'listening') | Enables listening for **listening** events of the UDPSocket connection. |
| on(type: 'listening') | Enables listening for **listening** events of the UDPSocket connection. |
| off(type: 'listening') | Disables listening for **listening** events of the UDPSocket connection. |
| off(type: 'listening') | Disables listening for **listening** events of the UDPSocket connection. |
| on(type: 'connect') | Enables listening for **connect** events of the TCPSocket connection. |
| on(type: 'connect') | Enables listening for **connect** events of the TCPSocket connection. |
| off(type: 'connect') | Disables listening for **connect** events of the TCPSocket connection.|
| off(type: 'connect') | Disables listening for **connect** events of the TCPSocket connection.|
@@ -12,20 +12,20 @@ If an error occurs in any of the preceding processes, the client will receive a
...
@@ -12,20 +12,20 @@ If an error occurs in any of the preceding processes, the client will receive a
The WebSocket connection function is mainly implemented by the WebSocket module. To use related APIs, you must declare the **ohos.permission.INTERNET** permission. The following table describes the related APIs.
The WebSocket connection function is mainly implemented by the WebSocket module. To use related APIs, you must declare the **ohos.permission.INTERNET** permission. The following table describes the related APIs.
| API| Description|
| API | Description |
| -------- | -------- |
| -------- | -------- |
| createWebSocket() | Creates a WebSocket connection.|
| createWebSocket() | Creates a WebSocket connection.|
| connect() | Establishes a WebSocket connection to a given URL.|
| connect() | Establishes a WebSocket connection to a given URL.|
| send() | Sends data through the WebSocket connection.|
| send() | Sends data through the WebSocket connection.|
| close() | Closes a WebSocket connection.|
| close() | Closes a WebSocket connection.|
| on(type: 'open') | Enables listening for **open** events of a WebSocket connection.|
| on(type: 'open') | Enables listening for **open** events of a WebSocket connection.|
| off(type: 'open') | Disables listening for **open** events of a WebSocket connection.|
| off(type: 'open') | Disables listening for **open** events of a WebSocket connection.|
| on(type: 'message') | Enables listening for **message** events of a WebSocket connection.|
| on(type: 'message') | Enables listening for **message** events of a WebSocket connection.|
| off(type: 'message') | Disables listening for **message** events of a WebSocket connection.|
| off(type: 'message') | Disables listening for **message** events of a WebSocket connection.|
| on(type: 'close') | Enables listening for **close** events of a WebSocket connection.|
| on(type: 'close') | Enables listening for **close** events of a WebSocket connection.|
| off(type: 'close') | Disables listening for **close** events of a WebSocket connection.|
| off(type: 'close') | Disables listening for **close** events of a WebSocket connection.|
| on(type: 'error') | Enables listening for **error** events of a WebSocket connection.|
| on(type: 'error') | Enables listening for **error** events of a WebSocket connection.|
| off(type: 'error') | Disables listening for **error** events of a WebSocket connection.|
| off(type: 'error') | Disables listening for **error** events of a WebSocket connection.|