final class · System.Net

TcpListener

public final class TcpListener

Accepts TCP connections on a port (0: one the system picks; see Port).

Tipo
final class
Espacio de nombres
System.Net
Ensamblado
System.Core
Acceso
public, final
Archivo fuente
Net.ant

Herencia

Clases base
Any TcpListener

Constructores

new(i32 port)
#

Propiedades

i32 Port { get; }
#

read-only

The port it listens on.

Métodos

Accept() : TcpClient
#

Waits for the next connection.

Close()
#

Miembros privados e internos (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

Miembros heredados (5)

Código fuente

TcpListener en Antril, descompilado a partir de su 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