|
|
|
@ -21,13 +21,13 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_service.Connecting = (client, e) => { //有客户端正在连接
|
|
|
|
|
_service.Connecting = (client, e) => {
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}正在接入服务");
|
|
|
|
|
};
|
|
|
|
|
_service.Connected = (client, e) => { //有客户端成功连接
|
|
|
|
|
_service.Connected = (client, e) => {
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}接入服务成功,Id:{client.ID}");
|
|
|
|
|
};
|
|
|
|
|
_service.Disconnected = (client, e) => { //有客户端断开连接
|
|
|
|
|
_service.Disconnected = (client, e) => {
|
|
|
|
|
_logger.LogInformation($"客户端{client.IP}断开连接,Id:{client.ID}");
|
|
|
|
|
};
|
|
|
|
|
_service.Received = (client, byteBlock, requestInfo) =>
|
|
|
|
@ -40,21 +40,20 @@ namespace SlnMesnac.TouchSocket
|
|
|
|
|
|
|
|
|
|
_service.Setup(new TouchSocketConfig()//载入配置
|
|
|
|
|
.SetListenIPHosts(new IPHost[] { new IPHost($"0.0.0.0:{serverPort}") })
|
|
|
|
|
//.SetDataHandlingAdapter(() => { return new MyFixedHeaderCustomDataHandlingAdapter(); })//配置适配器
|
|
|
|
|
.ConfigureContainer(a =>//容器的配置顺序应该在最前面
|
|
|
|
|
{
|
|
|
|
|
a.AddConsoleLogger();//添加一个控制台日志注入(注意:在maui中控制台日志不可用)
|
|
|
|
|
a.AddConsoleLogger();
|
|
|
|
|
})
|
|
|
|
|
.ConfigurePlugins(a =>
|
|
|
|
|
{
|
|
|
|
|
//a.Add<CheckClearPlugin>().SetDuration(new TimeSpan(0, 0, 0, 5, 0));
|
|
|
|
|
//自定义插件
|
|
|
|
|
}))
|
|
|
|
|
.Start();//启动
|
|
|
|
|
.Start();
|
|
|
|
|
_logger.LogInformation($"TcpServer启动成功,监听端口:{serverPort}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"采集服务启动异常:{ex}");
|
|
|
|
|
_logger.LogError($"TcpServer启动异常:{ex}");
|
|
|
|
|
throw new Exception(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|