Skip to content

Class ClientFrame

Namespace: Tool.Sockets.NetFrame
Assembly: Tool.Net.dll

封装的一个TCP框架(客户端)

csharp
public class ClientFrame : EnClientEventDrive

Inheritance

objectEnClientEventDriveClientFrame

Inherited Members

EnClientEventDrive.OnInterceptor(EnClient, bool), EnClientEventDrive.OnIsQueue(EnClient, bool), EnClientEventDrive.IsEvent(EnClient), EnClientEventDrive.IsQueue(EnClient), EnClientEventDrive.OpenAllEvent(), EnClientEventDrive.OpenAllQueue(), EnClientEventDrive.CloseAllEvent(), EnClientEventDrive.CloseAllQueue(), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Remarks

代码由逆血提供支持

Constructors

ClientFrame()

无参构造

csharp
public ClientFrame()

ClientFrame(NetBufferSize)

初始化包

csharp
public ClientFrame(NetBufferSize bufferSize)

Parameters

bufferSize NetBufferSize

收包规范

ClientFrame(NetBufferSize, bool)

初始化包

csharp
public ClientFrame(NetBufferSize bufferSize, bool IsReconnect)

Parameters

bufferSize NetBufferSize

收包规范

IsReconnect bool

是否在与服务器断开后主动重连?

Properties

Connected

获取一个值,该值指示 Client 的基础 Socket 是否已连接到远程主机。

csharp
public bool Connected { get; }

Property Value

bool

IsClose

标识客户端是否关闭

csharp
public bool IsClose { get; }

Property Value

bool

IsThreadPool

是否使用线程池调度接收后的数据(允许使用者初始化时设置,消息是否有序获取) 默认 true 开启

csharp
public bool IsThreadPool { get; init; }

Property Value

bool

LocalPoint

当前设备的连接信息

csharp
public Ipv4Port LocalPoint { get; }

Property Value

Ipv4Port

Server

服务器的连接信息

csharp
public UserKey Server { get; }

Property Value

UserKey

Methods

AddKeepAlive(byte)

添加持久化消息(心跳),防止特殊情况下的断开连接

csharp
public void AddKeepAlive(byte TimeInterval)

Parameters

TimeInterval byte

Close()

关闭连接,断开处于连接状态的服务器

csharp
public void Close()

ConnectAsync(int)

异步连接,连接ip地址为127.0.0.1

csharp
public Task ConnectAsync(int port)

Parameters

port int

要连接的服务器的端口

Returns

Task

ConnectAsync(string, int)

异步连接

csharp
public Task ConnectAsync(string ip, int port)

Parameters

ip string

要连接的服务器的ip地址

port int

要连接的服务器的端口

Returns

Task

Reconnection()

重连,返回是否重连,如果没有断开是不会重连的

csharp
public Task<bool> Reconnection()

Returns

Task<bool>

Send(ApiPacket)

同步发送消息

csharp
public NetResponse Send(ApiPacket api)

Parameters

api ApiPacket

接口调用信息

Returns

NetResponse

SendAsync(ApiPacket)

异步发送消息

csharp
public ValueTask<NetResponse> SendAsync(ApiPacket api)

Parameters

api ApiPacket

接口调用信息

Returns

ValueTask<NetResponse>

SendRelay(string, ApiPacket)

同步发送消息(转发给指定客户端)

csharp
public NetResponse SendRelay(string IpPort, ApiPacket api)

Parameters

IpPort string

事件处理的服务器

api ApiPacket

接口调用信息

Returns

NetResponse

SendRelayAsync(string, ApiPacket)

异步发送消息(转发给指定客户端)

csharp
public ValueTask<NetResponse> SendRelayAsync(string IpPort, ApiPacket api)

Parameters

IpPort string

事件处理的服务器

api ApiPacket

接口调用信息

Returns

ValueTask<NetResponse>

SetCompleted(CompletedEvent<EnClient>)

连接、发送、关闭事件

csharp
public void SetCompleted(CompletedEvent<EnClient> Completed)

Parameters

Completed CompletedEvent<EnClient>

基于Apache-2.0协议开源