一款简单易用的基础网络通讯组件库。

TcpSessionClient 类

定义了一个抽象类TcpSessionClient,用于处理TCP会话客户端的连接和数据传输。 它继承自TcpSessionClientBase类,并实现了ITcpSessionClient接口。 该类提供了基础的TCP会话管理功能,包括客户端的标识(Id)、IP地址(IP)和端口号(Port)。 使用DebuggerDisplay属性,可以在调试工具中更清晰地展示每个实例的Id、IP地址和端口号。 继承此类的子类通常需要实现或重写一些方法和属性,以适应特定的业务逻辑和数据处理需求。

Definition

命名空间: TouchSocket.Sockets
程序集: TouchSocket (在 TouchSocket.dll 中) 版本:3.0.0+ccaf96084d09f972257496d1dd63b8ba3c1e44f0
C#
public abstract class TcpSessionClient : TcpSessionClientBase, 
	ITcpSessionClient, ITcpSession, IClient, IDependencyObject, IDisposableObject, 
	IDisposable, ILoggerObject, IResolverConfigObject, IConfigObject, IPluginObject, 
	IResolverObject, IOnlineClient, IClosableClient, IClientSender, ISender, 
	IRequestInfoSender, IIdSender, IIdRequestInfoSender, ITcpListenableClient, ISessionClient, 
	IIdClient, IReceiverClient<IReceiverResult>
Inheritance
Object    DisposableObject    DependencyObject    ConfigObject    ResolverConfigObject    TcpSessionClientBase    TcpSessionClient
Implements
IDisposable, IConfigObject, IDependencyObject, IDisposableObject, ILoggerObject, IPluginObject, IResolverConfigObject, IResolverObject, IClient, IClientSender, IClosableClient, IIdClient, IIdRequestInfoSender, IIdSender, IOnlineClient, IReceiverClientIReceiverResult, IRequestInfoSender, ISender, ISessionClient, ITcpListenableClient, ITcpSession, ITcpSessionClient

构造函数

TcpSessionClient初始化 TcpSessionClient 类的一个新实例

属性

Closed 断开连接
Closing 即将断开连接(仅主动断开时有效)。

此事件标识在与 ITcpSessionClient 的连接即将主动断开时发生的事件。提供此事件是为了允许执行断开连接前的清理操作。

Config 配置项
(继承自 TcpSessionClientBase。)
DataHandlingAdapter 数据处理适配器
(继承自 TcpSessionClientBase。)
DisposedValue 标识该对象是否已被释放
(继承自 DisposableObject。)
Id 用于索引的Id
(继承自 TcpSessionClientBase。)
IP IP地址
(继承自 TcpSessionClientBase。)
IsClient 表示是否为客户端终端。当为时,表示是客户端。否则为服务器通讯终端。
(继承自 TcpSessionClientBase。)
LastReceivedTime 最后一次接收到数据的时间
(继承自 TcpSessionClientBase。)
LastSentTime 最后一次发送数据的时间
(继承自 TcpSessionClientBase。)
ListenOption 监听配置。

注意:一般情况下不要随意修改该值。


(继承自 TcpSessionClientBase。)
Logger 日志记录器
(继承自 ConfigObject。)
MainSocket 主通信器
(继承自 TcpSessionClientBase。)
Online 判断是否在线
(继承自 TcpSessionClientBase。)
PluginManager 插件管理器
(继承自 TcpSessionClientBase。)
Port 端口号
(继承自 TcpSessionClientBase。)
Protocol 终端协议
(继承自 TcpSessionClientBase。)
Resolver 获取解析器实例。
(继承自 TcpSessionClientBase。)
Service 包含此辅助类的主服务器类
(继承自 TcpSessionClientBase。)
ServiceIP 接收此客户端的服务器IP地址
(继承自 TcpSessionClientBase。)
ServicePort 接收此客户端的服务器端口
(继承自 TcpSessionClientBase。)
UseSsl 使用Ssl加密
(继承自 TcpSessionClientBase。)

方法

Abort 中止当前操作。
(继承自 TcpSessionClientBase。)
ClearReceiver 移除同步数据接收器
CloneTo 将当前对象的依赖项克隆到目标对象中
(继承自 DependencyObject。)
CloseAsync 关闭客户端。
(继承自 TcpSessionClientBase。)
CreateReceiver 获取一个同步数据接收器
Dispose 释放资源。内部已经处理了SuppressFinalize(Object)
(继承自 DisposableObject。)
Dispose(Boolean) 处置资源
(继承自 TcpSessionClientBase。)
EqualsDetermines whether the specified object is equal to the current object.
(继承自 Object。)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(继承自 Object。)
GetHashCodeServes as the default hash function.
(继承自 Object。)
GetTypeGets the Type of the current instance.
(继承自 Object。)
GetValueTValue 获取依赖注入的值,当没有注入时,会返回默认行为的值。
(继承自 DependencyObject。)
HasValueTValue 判断在当前对象中是否有已设置的属性值。
(继承自 DependencyObject。)
IdChanged 当Id更新的时候触发
(继承自 TcpSessionClientBase。)
MemberwiseCloneCreates a shallow copy of the current Object.
(继承自 Object。)
OnInitialized 当初始化完成时,执行在OnTcpConnecting(ConnectingEventArgs)之前。
(继承自 TcpSessionClientBase。)
OnTcpClosed 客户端已断开连接。
(重写 TcpSessionClientBaseOnTcpClosed(ClosedEventArgs))
OnTcpClosing 即将断开连接(仅主动断开时有效)。
(重写 TcpSessionClientBaseOnTcpClosing(ClosingEventArgs))
OnTcpConnected 当客户端完整建立Tcp连接。
(重写 TcpSessionClientBaseOnTcpConnected(ConnectedEventArgs))
OnTcpConnecting 客户端正在连接。
(重写 TcpSessionClientBaseOnTcpConnecting(ConnectingEventArgs))
OnTcpReceived 当收到适配器处理的数据时。
(重写 TcpSessionClientBaseOnTcpReceived(ReceivedDataEventArgs))
OnTcpReceiving 当收到原始数据
(继承自 TcpSessionClientBase。)
OnTcpSending 在数据即将通过TCP发送时触发,此方法用于通过插件机制拦截发送行为。 如果子类覆盖了此方法,则不会触发插件。
(继承自 TcpSessionClientBase。)
ProtectedClearReceiver 清除接收器对象。
(继承自 TcpSessionClientBase。)
ProtectedCreateReceiver 创建或获取接收器对象。
(继承自 TcpSessionClientBase。)
ProtectedDefaultSendAsync 异步发送数据,保护方法。 此方法用于在已建立的TCP连接上异步发送数据。 它首先检查当前实例是否已被处置,然后检查客户端是否已连接。 如果这些检查通过,它将调用OnTcpSending事件处理程序进行预发送处理, 最后通过TCP核心组件实际发送数据。
(继承自 TcpSessionClientBase。)
ProtectedResetIdAsync 直接重置内部Id。
(继承自 TcpSessionClientBase。)
ProtectedSendAsync(IListArraySegmentByte) 异步发送字节传输列表。
(继承自 TcpSessionClientBase。)
ProtectedSendAsync(IRequestInfo) 异步发送请求信息。
(继承自 TcpSessionClientBase。)
ProtectedSendAsync(ReadOnlyMemoryByte) 异步发送只读内存数据。
(继承自 TcpSessionClientBase。)
ProtectedTryGetClient 尝试通过Id获得对应的客户端
(继承自 TcpSessionClientBase。)
RemoveValueTValue 移除属性值。
(继承自 DependencyObject。)
ResetIdAsync 重新设置Id
(继承自 TcpSessionClientBase。)
SendAsync(IListArraySegmentByte) 异步组合发送数据。

该发送会经过适配器封装,具体封装内容由适配器决定。

SendAsync(IRequestInfo) 异步发送数据。

该发送会经过适配器封装,具体封装内容由适配器决定。

SendAsync(ReadOnlyMemoryByte) 异步发送数据。

该发送会经过适配器封装,具体封装内容由适配器决定。

SendAsync(String, ReadOnlyMemoryByte) 异步向对应Id的客户端发送数据
SendAsync(String, IRequestInfo) 异步发送指定标识符和请求信息的方法
SetAdapter 设置数据处理适配器。
(继承自 TcpSessionClientBase。)
SetValueTValue 设置依赖注入的值,如果值已经存在,将被覆盖。
(继承自 DependencyObject。)
ThrowIfConfigIsNull 如果Config为空,则抛出ArgumentNullException的异常。
(继承自 ConfigObject。)
ThrowIfDisposed 判断当前对象是否已经被释放。 如果已经被释放,则抛出ObjectDisposedException异常。
(继承自 DisposableObject。)
ToStringReturns a string that represents the current object.
(继承自 Object。)
TryGetValueTValue 尝试获取依赖注入的值,当没有注入时,会返回
(继承自 DependencyObject。)
TryRemoveValueTValue 尝试重置属性值,如果没有这个值,则返回
(继承自 DependencyObject。)

扩展方法

CloseWithTLV 使用TLV格式关闭TCP会话
(由 TLVClientExtensions 定义。)
CloseWithTLVAsync 发送TLV的Close报文,然后关闭当前客户端
(由 TLVClientExtensions 定义。)
CreateWaitingClient 为指定的 ITcpSessionClient 实例创建一个等待客户端。
(由 WaitingClientExtension 定义。)
CreateWaitingClient 为 ITcpSessionClient 类型的客户端创建一个等待客户端。
(由 WaitingClientExtension 定义。)
GetJsonRpcActionClient 获取基于Tcp协议或者WebSocket协议的双工JsonRpc端
(由 JsonRpcClientExtension 定义。)
Map
(由 Mapper 定义。)
Map
(由 Mapper 定义。)
MapTTarget
(由 Mapper 定义。)
PingWithTLV 发送Tag为Ping的报文,然后等待Pong回应。

当适配器不是TLVDataHandlingAdapter时,会抛出异常。


(由 TLVClientExtensions 定义。)
SafeDispose 安全性释放(不用判断对象是否为空)。不会抛出任何异常。

内部会判断DisposedValue的值,如果为,则不会再执行Dispose


(由 SystemExtension 定义。)
SafeDispose 安全性释放(不用判断对象是否为空)。不会抛出任何异常。
(由 SystemExtension 定义。)
ToJsonString 转换为Json
(由 SerializeConvert 定义。)

参见