mirror of
https://github.com/RRQM/TouchSocket.git
synced 2025-12-19 01:46:44 +08:00
新增(MyTcpPlugin, Startup): 扩展插件功能并更新配置
在 MyTcpPlugin.cs 中,扩展 MyTcpPlugin 类以实现 ITcpReceivedPlugin 接口,添加 OnTcpReceived 方法以处理数据接收事件。在 Startup.cs 中,更新 TCP 服务配置以明确指定监听的 IP 地址和端口,并修正注释以提高可读性。
This commit is contained in:
@@ -17,7 +17,7 @@ using TouchSocket.Sockets;
|
||||
|
||||
namespace TcpServiceForWebApi.Plugins;
|
||||
|
||||
public class MyTcpPlugin : PluginBase, ITcpConnectedPlugin
|
||||
public class MyTcpPlugin : PluginBase, ITcpConnectedPlugin, ITcpReceivedPlugin
|
||||
{
|
||||
private readonly ILogger<MyTcpPlugin> m_logger;
|
||||
|
||||
@@ -31,4 +31,10 @@ public class MyTcpPlugin : PluginBase, ITcpConnectedPlugin
|
||||
this.m_logger.LogInformation("客户端连接");
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
||||
{
|
||||
this.m_logger.LogInformation($"收到数据:{e.Memory.Span.ToUtf8String()}");
|
||||
await e.InvokeNext();
|
||||
}
|
||||
}
|
||||
@@ -36,10 +36,10 @@ public class Startup
|
||||
{
|
||||
services.AddTcpService(config =>
|
||||
{
|
||||
config.SetListenIPHosts(7789)
|
||||
config.SetListenIPHosts("tcp://127.0.0.1:7789")
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
a.Add<MyTcpPlugin>();//<EFBFBD>˲<EFBFBD><EFBFBD><EFBFBD>Ϳ<EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
a.Add<MyTcpPlugin>();//插件
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user