提交 aac929e9 编写于 作者: 若汝棋茗

更新demo

上级 e75525e2
......@@ -42,11 +42,6 @@ namespace AdapterConsoleApp
private static void StartTcpService()
{
TcpService service = new TcpService();
service.Connecting += (client, e) =>
{
//有客户端正在连接
client.SetDataHandlingAdapter(new MyCustomBetweenAndDataHandlingAdapter());
};
service.Connected += (client, e) => { };//有客户端连接
service.Disconnected += (client, e) => { };//有客户端断开连接
service.Received += (client, byteBlock, requestInfo) =>
......
......@@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocketPro" Version="0.2.2" />
<PackageReference Include="TouchSocketPro" Version="0.2.3" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -7,6 +7,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocketPro" Version="0.2.2" />
<PackageReference Include="TouchSocketPro" Version="0.2.3" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocket" Version="0.2.2" />
<PackageReference Include="TouchSocketPro" Version="0.2.3" />
</ItemGroup>
</Project>
......@@ -3,7 +3,9 @@ using TouchSocket.Core;
using TouchSocket.Core.ByteManager;
using TouchSocket.Core.Config;
using TouchSocket.Core.Log;
using TouchSocket.Core.Plugins;
using TouchSocket.Sockets;
using TouchSocket.Sockets.Plugins;
namespace NATServiceConsoleApp
{
......@@ -18,7 +20,7 @@ namespace NATServiceConsoleApp
service.Setup(config);
service.Start();
Console.WriteLine("转发服务器已启动。已将7788端口转发到127.0.0.1:7789与127.0.0.1:7790地址");
Console.WriteLine("转发服务器已启动。已将7788端口转发到127.0.0.1:7789地址");
}
}
......@@ -32,8 +34,15 @@ namespace NATServiceConsoleApp
{
//此处模拟的是只要连接到NAT服务器,就转发。
//实际上,这个方法可以随时调用。
socketClient.AddTargetClient(new TouchSocketConfig().SetRemoteIPHost("127.0.0.1:7789"));
socketClient.AddTargetClient(new TouchSocketConfig().SetRemoteIPHost("127.0.0.1:7790"));
socketClient.AddTargetClient(new TouchSocketConfig()
.SetRemoteIPHost("127.0.0.1:7789")
.ConfigurePlugins(a=>
{
//在企业版中,使用以下任意方式,可实现转发客户端的断线重连。
a.Add<PollingKeepAlivePlugin<TcpClient>>()
.SetTick(1000);//每秒检查
//a.UseReconnection();
}));
}
catch (Exception ex)
{
......
......@@ -32,16 +32,20 @@ namespace UdpDemoApp
}
};
if (checkBox1.Checked)
{
m_udpSession.SetDataHandlingAdapter(new UdpPackageAdapter());
}
else
{
m_udpSession.SetDataHandlingAdapter(new NormalUdpDataHandlingAdapter());
}
m_udpSession.Setup(new TouchSocketConfig()
.SetBindIPHost(new IPHost(this.textBox2.Text))
.SetUdpDataHandlingAdapter(()=>
{
if (checkBox1.Checked)
{
return new UdpPackageAdapter();
}
else
{
return new NormalUdpDataHandlingAdapter();
}
})
.ConfigureContainer(a =>
{
a.SetSingletonLogger(new LoggerGroup(new EasyLogger(this.ShowMsg), new FileLogger()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册