### Use Electron Sockets in Renderer Process Source: https://github.com/foxglove/electron-socket/blob/main/README.md This example shows how to create and use TCP server and client sockets within the Electron renderer process. It sets up a server listening on port 9000 and a client connecting to it, demonstrating basic data transfer and the asynchronous, Promise-based nature of the API. ```ts // renderer.ts /////////////////////////////////////////////////////////////// import { Sockets } from "@foxglove/electron-socket/renderer"; async function main() { const net = await Sockets.Create(); const server = await net.createServer(); server.on("connection", (client) => { client.write(new Uint8Array([42])); }); server.listen(9000); const socket = await net.createSocket(); socket.on("data", (data: Uint8Array) => console.log(`Server sent ${data}`)); socket.connect({ port: 9000, host: "localhost" }); } main(); ``` -------------------------------- ### Initialize Electron Sockets in Preloader Source: https://github.com/foxglove/electron-socket/blob/main/README.md This snippet demonstrates how to initialize the `PreloaderSockets` in the Electron preloader script. This step is crucial for exposing the socket functionality from the isolated preloader context to the renderer process, enabling network operations in the main application. ```ts // preload.ts //////////////////////////////////////////////////////////////// import { PreloaderSockets } from "@foxglove/electron-socket/preloader"; PreloaderSockets.Create(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.