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
Any TcpListener

Constructors

new(i32 port)
#

Properties

i32 Port { get; }
#

read-only

The port it listens on.

Methods

Accept() : TcpClient
#

Waits for the next connection.

Close()
#

Private and internal members (5)

i64 handle
#

private

static extern("net.listen") ListenOn(i64 port) : i64
#

private static

static extern("net.accept") AcceptOn(i64 listener) : i64
#

private static

static extern("net.port") PortOf(i64 handle) : i64
#

private static

static extern("stream.close") CloseHandle(i64 handle) : i64
#

private static

Inherited members (5)

Source

TcpListener as Antril, decompiled from its Larva HIR.

System.Net.TcpListener.ant
// 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);
			}
	}
}
Esc