final class · System.Net
TcpClient
public final class TcpClient
One TCP connection.
- Kind
- final class
- Namespace
- System.Net
- Assembly
- System.Core
- Access
- public, final
- Source file
Net.ant
Inheritance
- Base classes
-
AnyTcpClient
Constructors
Properties
NetworkStream Stream { get; }
#
Methods
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()
#
Private and internal members (2)
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
TcpClient as Antril, decompiled from its 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;
}
}
}