Class NetworkListener<ISocket>
Namespace: Tool.Sockets.Kernels
Assembly: Tool.Net.dll
通信公共模板抽象类(服务端版)
public abstract class NetworkListener<ISocket> : EnServerEventDrive, INetworkListener<ISocket>, INetworkListener, INetworkCore, IDisposableType Parameters
ISocket
Inheritance
object ← EnServerEventDrive ← NetworkListener<ISocket>
Implements
INetworkListener<ISocket>, INetworkListener, INetworkCore, IDisposable
Inherited Members
EnServerEventDrive.OnInterceptor(EnServer, bool), EnServerEventDrive.OnIsQueue(EnServer, bool), EnServerEventDrive.IsEvent(EnServer), EnServerEventDrive.IsQueue(EnServer), EnServerEventDrive.OpenAllEvent(), EnServerEventDrive.OpenAllQueue(), EnServerEventDrive.CloseAllEvent(), EnServerEventDrive.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
NetworkListener()
默认构造(公共模板信息)
protected NetworkListener()Properties
BufferSize
表示通讯的包大小
public virtual NetBufferSize BufferSize { get; protected init; }Property Value
IsClose
标识服务端连接是否关闭
public abstract bool IsClose { get; }Property Value
IsThreadPool
是否使用线程池调度接收后的数据 默认 true 开启
public virtual bool IsThreadPool { get; set; }Property Value
ListClient
已建立连接的集合 key:UserKey value:Socket
public abstract IReadOnlyDictionary<UserKey, ISocket> ListClient { get; }Property Value
IReadOnlyDictionary<UserKey, ISocket>
Millisecond
监听控制毫秒
public abstract int Millisecond { get; set; }Property Value
Server
服务器创建时的信息
public abstract UserKey Server { get; }Property Value
Methods
CreateSendBytes(ISocket, int)
创建数据发送空间
public abstract SendBytes<ISocket> CreateSendBytes(ISocket client, int length)Parameters
client ISocket
收数据的对象
length int
数据大小
Returns
SendBytes<ISocket>
Dispose()
关闭连接,回收相关资源
public abstract void Dispose()OnComplete(in UserKey, EnServer)
可供开发重写的事件方法
public abstract ValueTask<IGetQueOnEnum> OnComplete(in UserKey key, EnServer enAction)Parameters
key UserKey
指定发送对象
enAction EnServer
消息类型
Returns
SendAsync(SendBytes<ISocket>)
异步发送消息
public abstract ValueTask SendAsync(SendBytes<ISocket> sendBytes)Parameters
sendBytes SendBytes<ISocket>
数据包
Returns
SetCompleted(CompletedEvent<EnServer>)
连接、发送、关闭事件
public abstract void SetCompleted(CompletedEvent<EnServer> Completed)Parameters
Completed CompletedEvent<EnServer>
SetReceived(ReceiveEvent<ISocket>)
接收到数据事件
public abstract void SetReceived(ReceiveEvent<ISocket> Received)Parameters
Received ReceiveEvent<ISocket>
StartAsync(string, int)
开始异步监听ip地址的端口
public abstract Task StartAsync(string ip, int port)Parameters
ip string
port int
Returns
Stop()
TCP关闭
public abstract void Stop()TrySocket(in UserKey, out ISocket)
根据IP:Port获取对应的连接对象
public abstract bool TrySocket(in UserKey key, out ISocket client)Parameters
key UserKey
IP:Port
client ISocket
连接对象
Returns
返回成功状态