Import std.net.tcp
TcpListener
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-
@PanicsAtCaller Public Static Method Listen(address: SocketAddress, backlog: Int = BACKLOG): TcpListener Throws NetErrorstatic method #Listens at
address, whose port 0 has the OS pick one, which LocalAddress tells, keeping up tobacklogconnections 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 NetErrorstatic method #Listens at
host's first address, as Dns.Resolve gives them, andport. -
Where it listens, the port the OS picked included.
-
Whether Close closed it.
-
The next connection, waiting up to
timeoutfor 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, TimeoutErrormethod #Accept's Async twin, which waits on the main thread.
-
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.