2024-12-19 16:07:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using JiShe.CollectBus.Exceptions;
|
2024-10-29 16:28:14 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-09-30 17:10:43 +08:00
|
|
|
|
using TouchSocket.Core;
|
|
|
|
|
|
using TouchSocket.Sockets;
|
|
|
|
|
|
|
2024-12-19 16:07:07 +08:00
|
|
|
|
namespace JiShe.CollectBus.Plugins
|
2024-09-30 17:10:43 +08:00
|
|
|
|
{
|
2025-03-27 08:38:19 +08:00
|
|
|
|
public partial class TcpCloseMonitor(ILogger<TcpCloseMonitor> logger) : PluginBase, ITcpReceivedPlugin
|
2024-09-30 17:10:43 +08:00
|
|
|
|
{
|
2025-03-27 08:38:19 +08:00
|
|
|
|
|
|
|
|
|
|
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
2024-09-30 17:10:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
await e.InvokeNext();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (CloseException ex)
|
|
|
|
|
|
{
|
2024-10-29 16:28:14 +08:00
|
|
|
|
logger.LogInformation("拦截到CloseException");
|
2025-03-27 08:38:19 +08:00
|
|
|
|
await client.CloseAsync(ex.Message);
|
2024-09-30 17:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exx)
|
|
|
|
|
|
{
|
2025-03-27 08:38:19 +08:00
|
|
|
|
|
2024-09-30 17:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
2025-03-27 08:38:19 +08:00
|
|
|
|
|
2024-09-30 17:10:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-27 08:38:19 +08:00
|
|
|
|
public partial class UdpCloseMonitor(ILogger<TcpCloseMonitor> logger) : PluginBase, IUdpReceivedPlugin
|
2024-09-30 17:10:43 +08:00
|
|
|
|
{
|
2024-10-11 11:27:57 +08:00
|
|
|
|
public Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e)
|
2024-09-30 17:10:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|