Skip to content
FutureBlitz

    Install

    Import std.net.ipc

    std.net.ipc

    Connections between programs on one machine.

    std.net's IPC: IpcListener, which takes connections at a name, and IpcStream, a connection's bytes both ways, between programs on one machine. libuv chooses what a name is: a named pipe, \.\pipe<name>, on Windows, and a Unix socket, .sock in the temporary folder, elsewhere. A Reader and a Writer, blocking or Async, as TCP's are.

    std/net/ipc.fb

    Types

    IpcStream class

    Public Class IpcStream Implements Reader, Writer

    A connection to an IpcListener: bytes both ways, in order, which it reads and writes as std.io's streams do. A Read or Write that fails throws an IOError whose Cause is a NetError or a TimeoutError. It closes when it goes, or at Close, which the other side reads as its end. A named pipe can't end one way only, so it has no ShutdownWrite, as a TcpStream has.

    Examples

    Local stream = Try IpcStream.Connect("example-app")
    Try stream.WriteText("hello")
    Print(Try ReadAllText(stream))
    stream.Close()

    std/net/ipc.fb, line 36

    • @PanicsAtCaller Public Static Method Connect(name: String, timeout: Duration? = Null): IpcStream Throws NetError, TimeoutError static method #

      Connects to the IpcListener of name, waiting up to timeout, or as long as it takes for a Null one. Throws a NetError of REFUSED when nothing listens at it, and a TimeoutError when it takes too long. A name that isn't one panics.

    • @PanicsAtCaller Public Static Async Method ConnectAsync(name: String, timeout: Duration? = Null): IpcStream Throws NetError, TimeoutError static method #

      Connect's Async twin, which waits on the main thread.

    • Public Property Name: String property #

      The name of the listener it's connected to, or that it came to.

    • Public Property ReadTimeout: Duration? property #

      How long a Read or ReadAsync waits for bytes before it throws, or Null, as it starts, to wait as long as it takes.

    • Public Property IsClosed: Bool property #

      Whether Close closed it.

    • Public Method Read(into: Buffer<UInt8>): Int64 Throws IOError method #

      Reads what's come, at least a byte, waiting for some, or 0 once the other side ended what it writes.

    • Public Async Method ReadAsync(into: Buffer<UInt8>): Int64 Throws IOError method #

      Read's Async twin, which waits on the I/O thread for the connection's bytes while the main thread goes on.

    • Public Method Write(from: Buffer<UInt8>) Throws IOError method #

      Writes all of from's bytes, returning once the OS has them.

    • Public Async Method WriteAsync(from: Buffer<UInt8>) Throws IOError method #

      Write's Async twin, which waits on the I/O thread while the connection's bytes go, while the main thread goes on.

    • Public Method Close() method #

      Closes it at once: a Read or Write waiting for it throws an IOError whose Cause is a NetError of CLOSED, and so does one after. Going closes it too.

    IpcListener class

    Public Class IpcListener

    Takes connections at a name, from programs on the same machine, which Accept gives as IpcStreams. It closes when it goes, or at Close, with the connections nothing accepted, and its name is free again, but on Windows, where a named pipe is there until its connections close too, both ends: a connection to it meanwhile waits, for up to 30 seconds.

    Examples

    Local listener = Try IpcListener.Listen("example-app")
    Local client = Try listener.Accept()
    Try client.WriteText("hello from the server")
    client.Close()

    std/net/ipc.fb, line 128

    • @PanicsAtCaller Public Static Method Listen(name: String, backlog: Int = BACKLOG): IpcListener Throws NetError static method #

      Listens at name: 1 to 64 ASCII letters, digits, '.', '-', and '_', or it panics, with a backlog of 1 at least. A name is the same whatever its letters' case, as Windows' named pipes are, so "App" and "app" are one name on every OS. Throws a NetError when something listens at it already. A Unix socket's file that a program left when it ended without closing its listener is taken over, and any other file there stays.

    • Public Property Name: String property #

      Where it listens.

    • Public Property IsClosed: Bool property #

      Whether Close closed it.

    • Public Method Accept(timeout: Duration? = Null): IpcStream Throws NetError, TimeoutError method #

      The next connection, waiting up to timeout for one, or as long as it takes for a Null one, and throwing a TimeoutError after.

    • Public Async Method AcceptAsync(timeout: Duration? = Null): IpcStream Throws NetError, TimeoutError method #

      Accept's Async twin, which waits on the main thread.

    • Public Method Close() method #

      Closes it at once, with the connections nothing accepted: what's waiting for it throws a NetError of CLOSED, and so does what uses it after. Going closes it too.

    Report an issue with this page or with FutureBlitz on GitHub.