Files
archived-tauri-docs/src/content/docs/concepts/Inter-Process Communication/index.mdx
Simon Hyll dfc1f3bc5c feat: site restructuring (#2082)
* merge conflicts resolved

* fix: link validation

* fix: ordering

* fix: js renamed to javascript

* fix: removed accidentally committed generated files

* fix: removed tauri

* fix: added tauri

* fix: releases should only be built in prod
2024-04-22 21:33:22 +02:00

63 lines
2.7 KiB
Plaintext

---
title: Inter-Process Communication
sidebar:
label: Overview
order: 1
badge:
text: WIP
variant: caution
---
import { CardGrid, LinkCard } from '@astrojs/starlight/components';
Inter-Process Communication (IPC) allows isolated processes to communicate securely and is key to building more complex applications.
Learn more above the specific IPC patterns in the following guides:
<CardGrid>
<LinkCard
title="Brownfield"
href="/concepts/inter-process-communication/brownfield"
/>
<LinkCard
title="Isolation"
href="/concepts/inter-process-communication/isolation"
/>
</CardGrid>
Tauri uses a particular style of Inter-Process Communication called [Asynchronous Message Passing], where processes exchange _requests_ and _responses_ serialized using some simple data representation. Message Passing should sound familiar to anyone with web development experience, as this paradigm is used for client-server communication on the internet.
Message passing is a safer technique than shared memory or direct function access because the recipient is free to reject or discard requests as it sees fit. For example, if the Tauri Core process determines a request to be malicious, it simply discards the requests and never executes the corresponding function.
In the following, we explain Tauri's two IPC primitives - `Events` and `Commands` - in more detail.
## Events
Events are fire-and-forget, one-way IPC messages that are best suited to communicate lifecycle events and state changes. Unlike [Commands](#commands), Events can be emitted by both the Frontend _and_ the Tauri Core.
<figure>
![IPC Diagram](../../../../assets/concepts/events.svg)
<figcaption>Figure 1-2: An event sent from the Core to the Frontend.</figcaption>
</figure>
## Commands
Tauri also provides a [foreign function interface]-like abstraction on top of IPC messages[^1]. The primary API, `invoke`, is similar to the browser's `fetch` API and allows the Frontend to invoke Rust functions, pass arguments, and receive data.
Because this mechanism uses a [JSON-RPC] like protocol under the hood to serialize requests and responses, all arguments and return data must be serializable to JSON.
<figure>
![IPC Diagram](../../../../assets/concepts/commands.svg)
<figcaption>Figure 1-3: IPC messages involved in a command invocation.</figcaption>
</figure>
[^1]: Because Commands still use message passing under the hood, they do not share the same security pitfalls as real FFI interfaces do.
[asynchronous message passing]: https://en.wikipedia.org/wiki/Message_passing#Asynchronous_message_passing
[json-rpc]: https://www.jsonrpc.org
[foreign function interface]: https://en.wikipedia.org/wiki/Foreign_function_interface