Skip to content

Class NetworkConnect<ISocket>

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

通信公共模板抽象类(客户端版)

csharp
public abstract class NetworkConnect<ISocket> : EnClientEventDrive, INetworkConnect<ISocket>, INetworkConnect, INetworkCore, IDisposable

Type Parameters

ISocket

Inheritance

objectEnClientEventDriveNetworkConnect<ISocket>

Implements

INetworkConnect<ISocket>, INetworkConnect, INetworkCore, IDisposable

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

NetworkConnect()

默认构造(公共模板信息)

csharp
protected NetworkConnect()

Properties

BufferSize

表示通讯的包大小

csharp
public virtual NetBufferSize BufferSize { get; protected init; }

Property Value

NetBufferSize

Connected

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

csharp
public abstract bool Connected { get; }

Property Value

bool

IsClose

标识客户端是否关闭,改状态为调用关闭方法后的状态。

csharp
public abstract bool IsClose { get; }

Property Value

bool

IsThreadPool

是否使用线程池调度接收后的数据 默认 true 开启

csharp
public virtual bool IsThreadPool { get; set; }

Property Value

bool

LocalPoint

当前设备的连接信息

csharp
public abstract Ipv4Port LocalPoint { get; }

Property Value

Ipv4Port

Millisecond

监听控制毫秒

csharp
public abstract int Millisecond { get; set; }

Property Value

int

Server

服务器的连接信息

csharp
public abstract UserKey Server { get; }

Property Value

UserKey

Methods

Close()

TCP关闭

csharp
public abstract void Close()

ConnectAsync(string, int)

异步连接

csharp
public abstract Task ConnectAsync(string ip, int port)

Parameters

ip string

要连接的服务器的ip地址

port int

要连接的服务器的端口

Returns

Task

CreateSendBytes(int)

创建数据发送空间

csharp
public abstract SendBytes<ISocket> CreateSendBytes(int length)

Parameters

length int

数据大小

Returns

SendBytes<ISocket>

Dispose()

关闭连接,回收相关资源

csharp
public abstract void Dispose()

OnComplete(in UserKey, EnClient)

可供开发重写的事件方法

csharp
public abstract ValueTask<IGetQueOnEnum> OnComplete(in UserKey key, EnClient enAction)

Parameters

key UserKey

IP:端口

enAction EnClient

消息类型

Returns

ValueTask<IGetQueOnEnum>

Reconnection()

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

csharp
public abstract Task<bool> Reconnection()

Returns

Task<bool>

SendAsync(SendBytes<ISocket>)

异步发送消息

csharp
public abstract ValueTask SendAsync(SendBytes<ISocket> sendBytes)

Parameters

sendBytes SendBytes<ISocket>

数据包

Returns

ValueTask

SetCompleted(CompletedEvent<EnClient>)

连接、发送、关闭事件

csharp
public abstract void SetCompleted(CompletedEvent<EnClient> Completed)

Parameters

Completed CompletedEvent<EnClient>

SetReceived(ReceiveEvent<ISocket>)

接收到数据事件

csharp
public abstract void SetReceived(ReceiveEvent<ISocket> Received)

Parameters

Received ReceiveEvent<ISocket>

基于Apache-2.0协议开源