change - Tcp修改

pull/1/head
wenjy 10 months ago
parent 167a577194
commit 1bcabc1199

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

Loading…
Cancel
Save