final class · System.Net
TcpListener
public final class TcpListener
Accepts TCP connections on a port (0: one the system picks; see Port).
- Kind
- final class
- Namespace
- System.Net
- Assembly
- System.Core
- Access
- public, final
- Source file
Net.ant
Inheritance
- Base classes
-
AnyTcpListener
Constructors
Properties
Methods
Private and internal members (5)
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
TcpListener as Antril, decompiled from its Larva HIR.
// System.Net.TcpListener — System.Core (decompiled from Larva HIR)
import System.IO;
into namespace System.Net
{
/// Accepts TCP connections on a port (0: one the system picks; see Port).
public final class TcpListener
{
i64 handle;
static extern("net.listen") ListenOn(i64 port) : i64;
static extern("net.accept") AcceptOn(i64 listener) : i64;
static extern("net.port") PortOf(i64 handle) : i64;
static extern("stream.close") CloseHandle(i64 handle) : i64;
public:
new(i32 port)
{
handle = ListenOn(port);
if (handle < 0)
throw new IOError("cannot listen on port " + port);
}
/// Waits for the next connection.
Accept() : TcpClient
{
i64 connection = AcceptOn(handle);
if (connection < 0)
throw new IOError("accept failed");
return new TcpClient(connection);
}
Close()
{
if (handle >= 0)
CloseHandle(handle);
handle = -1;
}
/// The port it listens on.
i32 Port
{
get => (i32)PortOf(handle);
}
}
}