Class TcpClient
Represents a TCP client. Used to manage the TCP connection to a server.
Inheritance
Implements
Inherited Members
Namespace: Cosmos.System.Network.IPv4.TCP
Assembly: Cosmos.System2.dll
Syntax
public class TcpClient : IDisposable
Constructors
| Improve this Doc View SourceTcpClient(Address, Int32)
Initializes a new instance of the TcpClient class.
Declaration
public TcpClient(Address dest, int destPort)
Parameters
Type | Name | Description |
---|---|---|
Address | dest | Destination address. |
System.Int32 | destPort | Destination port. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
System.ArgumentException | Thrown if TcpClient with localPort 0 exists. |
TcpClient(Int32)
Initializes a new instance of the TcpClient class.
Declaration
public TcpClient(int localPort)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | localPort | The local port. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
System.ArgumentException | Thrown if localPort already exists. |
Fields
| Improve this Doc View SourceStateMachine
The TCP state machine.
Declaration
public Tcp StateMachine
Field Value
Type | Description |
---|---|
Tcp |
Properties
| Improve this Doc View SourceLocalEndPoint
Gets the remote hosts end-point (IP address and port).
Declaration
public EndPoint LocalEndPoint { get; }
Property Value
Type | Description |
---|---|
EndPoint |
RemoteEndPoint
Gets the remote hosts end-point (IP address and port).
Declaration
public EndPoint RemoteEndPoint { get; }
Property Value
Type | Description |
---|---|
EndPoint |
Methods
| Improve this Doc View SourceClose()
Closes the connection.
Declaration
public void Close()
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown on fatal error. |
System.Exception | Thrown if TCP Status is CLOSED. |
Connect(Address, Int32, Int32)
Connects the client to the given server.
Declaration
public void Connect(Address dest, int destPort, int timeout = 5000)
Parameters
Type | Name | Description |
---|---|---|
Address | dest | Destination address. |
System.Int32 | destPort | Destination port. |
System.Int32 | timeout |
Exceptions
Type | Condition |
---|---|
System.Exception | Thrown if TCP Status is not CLOSED. |
Dispose()
Declaration
public void Dispose()
IsConnected()
Returns a value whether the TCP client is connected to a remote host.
Declaration
public bool IsConnected()
Returns
Type | Description |
---|---|
System.Boolean |
NonBlockingReceive(ref EndPoint)
Receives data from the end-point.
Declaration
public byte[] NonBlockingReceive(ref EndPoint source)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | source | Source end point. |
Returns
Type | Description |
---|---|
System.Byte[] |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown on fatal error. |
System.Exception | Thrown if TCP Status is not ESTABLISHED. |
Receive(ref EndPoint)
Receives data from the end-point.
Declaration
public byte[] Receive(ref EndPoint source)
Parameters
Type | Name | Description |
---|---|---|
EndPoint | source | Source end point. |
Returns
Type | Description |
---|---|
System.Byte[] |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown on fatal error. |
System.Exception | Thrown if TCP Status is not ESTABLISHED. |
Send(Byte[])
Sends data to the connected server.
Declaration
public void Send(byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | Data array to send. |
Exceptions
Type | Condition |
---|---|
System.Exception | Thrown if destination is null or destinationPort is 0. |
System.ArgumentException | Thrown on fatal error. |
System.OverflowException | Thrown if data array length is greater than Int32.MaxValue. |
System.IO.IOException | Thrown on IO error. |
System.Exception | Thrown if TCP Status is not ESTABLISHED. |