Merge branch 'master' of http://www.scserverddns.top:13000/sc/SunlightAggregationManager
This commit is contained in:
commit
3840701756
4 files changed
+221
-62
No files matched your search
@@ -9,7 +9,6 @@ using System.Windows.Markup;
|
||||
using System.Xml.Linq;
|
||||
using TouchSocket.Core;
|
||||
using TouchSocket.Sockets;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
@@ -236,64 +235,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
)
|
||||
).ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class MyTcpService : TcpService<MyTcpSessionClient>
|
||||
{
|
||||
protected override MyTcpSessionClient NewClient()
|
||||
{
|
||||
return new MyTcpSessionClient();
|
||||
}
|
||||
}
|
||||
|
||||
class MyTcpSessionClient : TcpSessionClient
|
||||
{
|
||||
internal void SetDataHandlingAdapter(SingleStreamDataHandlingAdapter adapter)
|
||||
{
|
||||
base.SetAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 此插件实现,按照不同端口,使用不同适配器。
|
||||
/// <list type="bullet">
|
||||
/// <item>7789端口:使用"**"结尾的数据</item>
|
||||
/// <item>7790端口:使用"##"结尾的数据</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
internal class DifferentProtocolPlugin : PluginBase, ITcpConnectingPlugin, ITcpReceivedPlugin
|
||||
{
|
||||
public async Task OnTcpConnecting(ITcpSession client, ConnectingEventArgs e)
|
||||
{
|
||||
if (client is MyTcpSessionClient sessionClient)
|
||||
{
|
||||
if (sessionClient.ServicePort == 7789)
|
||||
{
|
||||
sessionClient.SetDataHandlingAdapter(new TerminatorPackageAdapter("**"));
|
||||
}
|
||||
else
|
||||
{
|
||||
sessionClient.SetDataHandlingAdapter(new TerminatorPackageAdapter("##"));
|
||||
}
|
||||
}
|
||||
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
||||
{
|
||||
//如果是自定义适配器,此处解析时,可以判断e.RequestInfo的类型
|
||||
|
||||
if (client is ITcpSessionClient sessionClient)
|
||||
{
|
||||
sessionClient.Logger.Info($"{sessionClient.GetIPPort()}收到数据,服务器端口:{sessionClient.ServicePort},数据:{e.Memory.Span.ToString(Encoding.UTF8)}");
|
||||
}
|
||||
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user