Import std.net.tcp
std.net.tcp
std.net's TCP: TcpListener, which takes connections at an address, and TcpStream, a connection's bytes both ways, a Reader and a Writer as std.io's streams are, each blocking or Async.
std/net/tcp.fb
Types
TcpStream
class
Public Class TcpStream Implements Reader, Writer
A TCP connection: bytes both ways, in order, which it reads and writes as std.io's streams do. Nagle's algorithm is off, so a small write goes at once, as a game's messages need. A Read or Write that fails throws an IOError whose Cause is a NetError, of RESET for a connection the other side ended badly, or a TimeoutError. It closes when it goes, or at Close.
-
Public Static Method Connect(address: SocketAddress, timeout: Duration? = Null): TcpStream Throws NetError, TimeoutErrorstatic method #Connects to
address, waiting up totimeout, or as long as the OS does for a Null one. Throws a NetError of REFUSED when nothing listens there, of UNREACHABLE when the network can't get there, and a TimeoutError when it takes too long. -
Public Static Method Connect(host: String, port: UInt16, timeout: Duration? = Null): TcpStream Throws NetError, TimeoutErrorstatic method #Connects to
hostatport, trying its addresses in the order Dns.Resolve gives them, each for up totimeout, and throws what the last one did when none connects. -
Public Static Async Method ConnectAsync(address: SocketAddress, timeout: Duration? = Null): TcpStream Throws NetError, TimeoutErrorstatic method #Connect's Async twin, which waits on the main thread.
-
Public Static Async Method ConnectAsync(host: String, port: UInt16, timeout: Duration? = Null): TcpStream Throws NetError, TimeoutErrorstatic method #Connect's Async twin to a host, through Dns.ResolveAsync.
-
Its own address.
-
The other side's address.
-
How long a Read or ReadAsync waits for bytes before it throws, or Null, as it starts, to wait as long as it takes.
-
Whether Close closed it.
-
Reads what's come, at least a byte, waiting for some, or 0 once the other side ended what it writes.
-
Read's Async twin, which waits on the main thread instead of blocking it. One that can only block reads with Read.
Doc from
std.io.streams.Reader.ReadAsync. -
Writes all of from's bytes, returning once the OS has them.
-
Write's Async twin, which waits on the main thread instead of blocking it.
Doc from
std.io.streams.Writer.WriteAsync. -
Ends what it writes, once what's written is sent, so the other side reads its end; it still reads what the other side writes.
-
What ShutdownWrite does, without blocking its thread: a call gives its Task.
-
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.
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.
-
@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 yet, 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.