🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

HarmonyOS IPC Kit Advanced: Basic Communication between Client and Server

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

This article aims to deeply explore the technical details of the Huawei HarmonyOS Next system (up to API 12 as of now), and is summarized based on actual development practices. It mainly serves as a carrier for technical sharing and communication. Mistakes and omissions are inevitable. Colleagues are welcome to put forward valuable opinions and questions so that we can make progress together. This article is original content, and any form of reprint must indicate the source and the original author.

This article will deeply explore how to use the IPC Kit to achieve basic communication between the client (Client) and the server (Server), and analyze the roles of Proxy and Stub in the communication process.





Communication Process between Client and Server





  1. Server Registers Capability: The Server side first needs to register its own capabilities (System Ability) with the System Ability Manager (SAMgr).


  2. Client Obtains Proxy: The Client side obtains the Proxy object of the corresponding capability from the SAMgr.


  3. Client Sends Request: The Client side sends a request to the Server side through the Proxy object.


  4. Server Processes Request: The Stub object on the Server side receives and processes the request from the Client side.


  5. Server Returns Result: The Server side returns the processing result to the Client side.


  6. Client Receives Result: The Client side receives the result returned by the Server side.
    ### Roles of Proxy and Stub


  7. Proxy: The proxy object on the Client side is used to forward the Client's request to the Server side. The Proxy object has the same method interface as the Server side, and the Client side sends requests by calling the methods of the Proxy object.


  8. Stub: The proxy object on the Server side is used to receive the request from the Client side and call the methods of the Server. The Stub object implements the method interface of the Server side and is responsible for handling the request from the Client side.
    ### Implementation of IPC Client Proxy and Server Stub


  9. Server Side:
        - Create an OHIPCRemoteStub object.
        - Implement the methods of the server side and handle the request from the Client side in the OnRemoteRequest callback function.
        - Register the service with the SAMgr.


  10. Client Side:
        - Obtain the Proxy object of the corresponding capability.
        - Send a request through the Proxy object.
        - Receive the result returned by the Server side.
    ### Using IPC Kit to Create Remote Proxy and Stub





CODE
// Server side
OHIPCRemoteStub *stub = OH_IPCRemoteStub_Create("com.example.service", &MyService::OnRemoteRequest, nullptr, this);
OH_IPCRemoteStub_RegisterSystemAbility(stub, MY_SERVICE_ID);
// Client side
OHIPCRemoteProxy *proxy = OH_IPCRemoteProxy_Create(MY_SERVICE_ID, "com.example.service");









Implementation of Asynchronous Communication Mode



The IPC Kit supports the asynchronous communication mode. The Client side can send a request and return immediately without waiting for the Server side to complete the processing. After the Server side completes the processing, it will return the result to the Client side through a callback function.




CODE
// Client side
OH_IPC_MessageOption option = { OH_IPC_REQUEST_MODE_ASYNC, 0 };
OH_IPCRemoteProxy_SendRequest(proxy, MY_METHOD_ID, data, nullptr, &option);
// Server side
int MyService::OnRemoteRequest(uint32_t code, const OHIPCParcel *data, OHIPCParcel *reply, void *userData) {
    // Process the request
    //...
    // Return the result
    OH_IPCRemoteProxy_SendRequest(proxy, MY_METHOD_ID, data, reply, &option);
}









Code Example: Basic Communication Code between IPC Client and Server






CODE
// Server side
class MyService : public OHIPCRemoteStub {
public:
    MyService() : OHIPCRemoteStub("com.example.service", &MyService::OnRemoteRequest) {}
    ~MyService() override {
        OH_IPCRemoteStub_Destroy(this);
    }
    int Add(int a, int b, int *result) {
        *result = a + b;
        return OH_IPC_SUCCESS;
    }
    static int OnRemoteRequest(uint32_t code, const OHIPCParcel *data, OHIPCParcel *reply, void *userData) {
        MyService *service = reinterpret_cast<MyService *>(userData);
        if (service == nullptr) {
            return OH_IPC_CHECK_PARAM_ERROR;
        }
        int a = 0, b = 0;
        OH_IPCParcel_ReadInt32(data, &a);
        OH_IPCParcel_ReadInt32(data, &b);
        int result = 0;
        service->Add(a, b, &result);
        OH_IPCParcel_WriteInt32(reply, result);
        return OH_IPC_SUCCESS;
    }
private:
    int MY_METHOD_ID = 1;
};
// Client side
OHIPCRemoteProxy *proxy = OH_IPCRemoteProxy_Create(MY_SERVICE_ID, "com.example.service");
OH_IPC_MessageOption option = { OH_IPC_REQUEST_MODE_SYNC, 0 };
OH_IPCParcel data, reply;
OH_IPCParcel_WriteInt32(&data, 1);
OH_IPCParcel_WriteInt32(&data, 2);
OH_IPCRemoteProxy_SendRequest(proxy, MY_METHOD_ID, &data, &reply, &option);
int result = 0;
OH_IPCParcel_ReadInt32(&reply, &result);
printf("Result: %d\n", result);









Summary



This article introduced in detail how to use the IPC Kit to achieve basic communication between the client and the server, and analyzed the roles of Proxy and Stub in the communication process. By understanding these concepts and code examples, we can easily build our own client - server applications and use the IPC Kit to achieve efficient inter - process communication.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten HarmonyOS IPC Kit Advanced: Basic Communication between Client and Server

Thematisch verwandte Begriffe: HarmonyOS, Advanced, Basic, Communication · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...