Simple IPC for Deno

Actions-Test Actions-Release

The simple and lightweight module that wraps Deno.listen() and Deno.connect() for basic inter-process communication (IPC) in Deno.

Example

This module is for Deno, but it's really raw socket communication, so it's compatible with processes on any different platforms.

Show more details...

Server: TCP/IP

// Without response.
listenIpBroadcast(0, (data:string)=>{
    console.log(data); // => "ping"
});

// With response.
listenIpRequest(0, (data:string)=>{
    console.log(data); // => "ping"
    return "pong";
});

Server: UnixSocket

// Without response.
listenUdsBroadcast("example_channel", (data:string)=>{
    console.log(data); // => "ping"
});

// With response.
listenUdsRequest("example_channel", (data:string)=>{
    console.log(data); // => "ping"
    return "pong";
});

Client: TCP/IP

// Without response.
await postIpBroadcast("example_channel", "ping");

// With response.
const response = await postIpRequest<string, string>(0, "ping");
console.log(response); // => "pong"

Client: UnixSocket

// Without response.
await postUdsBroadcast("example_channel", "ping");

// With response.
const response = await postUdsRequest<string, string>("example_channel", "ping");
console.log(response); // => "pong"

Details

With Deno's feature, you can choose between two communication methods.

  • TCP/IP Socket
  • Unix Socket

TCP/IP Socket

As for the general TCP/IP method, this can be done by listening to a port on localhost 127.0.0.1.

Unlike Unix Socket, which is described later, this is a better option because it can be used regardless of platform.

However UnixSocket is often faster in terms of performance.

Unix Socket

Unix method on the other hand, are a bit special, and cannot be used unless Deno's --unstable flag is enabled.

I hope it will be "stable".

Also the platform is only availables with Linux and Mac, not Windows.

This is not Deno's problem, but because the Rust library "tokio-rs/mio" that Deno uses internally does not support "AF_UNIX" on Windows.

Windows itself supports "AF_UNIX" in 10 insider build 17063, and a pull request has been submitted for support in "mio", so it may be possible to use it in Deno soon.

Reference: https://github.com/tokio-rs/mio/pull/1610

The path of the socket file is temporary directory /tmp/.${channel_string}.sock.

Also as mentioned above temporary directory C:/Windows/Temp is already defined for Windows in consideration of the possibility that Windows will be supported in the future.

API

See Deno Document for details.