final class · System.Net
TcpClient
public final class TcpClient
One TCP connection.
- Tipo
- final class
- Espacio de nombres
- System.Net
- Ensamblado
- System.Core
- Acceso
- public, final
- Archivo fuente
Net.ant
Herencia
- Clases base
-
AnyTcpClient
Constructores
Propiedades
NetworkStream Stream { get; }
#
Métodos
Connects to host (a name or an address) at port.
Write(str text)
#
Writes the text's UTF-8 bytes.
Reads what has arrived, up to max bytes, as text (empty when the other end closed).
Close()
#
Miembros privados e internos (2)
Miembros heredados (5)
GetTypemétodo de AnyUndescribedmétodo de AnyToStringmétodo de AnyHashmétodo de Anydestroymétodo de Any
Código fuente
TcpClient en Antril, descompilado a partir de su Larva HIR.
// System.Net.TcpClient — System.Core (decompiled from Larva HIR)
import System;
import System.IO;
into namespace System.Net
{
/// One TCP connection.
public final class TcpClient
{
NetworkStream stream;
static extern("net.connect") ConnectTo(u16[] host, i64 port) : i64;
public:
new(i64 handle)
{
stream = new NetworkStream(handle);
}
/// Connects to `host` (a name or an address) at `port`.
static Connect(str host, i32 port) : TcpClient
{
i64 handle = ConnectTo(Unicode.ToUtf16(host), port);
if (handle < 0)
throw new IOError("cannot connect to " + host + ":" + port);
return new TcpClient(handle);
}
/// Writes the text's UTF-8 bytes.
Write(str text)
{
u8[] bytes = text.Units();
stream.Write(bytes, 0, bytes.Length);
}
/// Reads what has arrived, up to `max` bytes, as text (empty when the other end closed).
Read(i32 max) : str
{
u8[] buffer = new u8[max];
i32 n = stream.Read(buffer, 0, max);
if (n <= 0)
return "";
u8[] got = new u8[n];
Array.Copy(buffer, 0, got, 0, n);
return new str(got);
}
Close()
{
stream.Close();
}
NetworkStream Stream
{
get => stream;
}
}
}