Skip to content
FutureBlitz

    Install

    Import std.net.tcp

    TcpListener

    std.net.tcp

    class

    Public Class TcpListener

    Takes TCP connections at an address, which Accept gives as TcpStreams. It closes when it goes, or at Close, with the connections it has that nothing accepted.

    Examples

    Local listener = Try TcpListener.Listen("127.0.0.1", 9000)
    Loop
        Local client = Try listener.Accept()
        Try client.WriteText("hello\n")
        client.Close()
    End Loop

    std/net/tcp.fb, line 177

    • @PanicsAtCaller Public Static Method Listen(address: SocketAddress, backlog: Int = BACKLOG): TcpListener Throws NetError static method #

      Listens at address, whose port 0 has the OS pick one, which LocalAddress tells, keeping up to backlog connections the OS has that aren't taken, 1 at least, or it panics. Throws a NetError when it can't, as when something listens there already.

    • @PanicsAtCaller Public Static Method Listen(host: String, port: UInt16, backlog: Int = BACKLOG): TcpListener Throws NetError static method #

      Listens at host's first address, as Dns.Resolve gives them, and port.

    • Public Property LocalAddress: SocketAddress property #

      Where it listens, the port the OS picked included.

    • Public Property IsClosed: Bool property #

      Whether Close closed it.

    • Public Method Accept(timeout: Duration? = Null): TcpStream 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): TcpStream 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.