-
大小: 21.19MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-08-06
- 语言: 其他
- 标签: SuperSocket SuperSocketD
资源简介
这个代码的优点是采用自定义命令行协议以及自定义命令过滤器,执行效率高,可扩展性能强,这都是日常工作敲出来可以正常工作的,欢迎大家下载.有问题请留言!
代码片段和文件信息
using System;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows.Forms;
using SuperSocket.ClientEngine;
using SuperSocketClient.Appbase;
using SuperSocketClient.Common;
namespace SuperSocketClient
{
public partial class Form1 : Form
{
private EasyClient client;
// private Timer timer1;
/////////////////////////////////////////////////////////////////////////////
#region 解决跨线程调用UI组件问题
private void DelegateAction(Action action)
{
if (InvokeRequired)
{
Invoke(action);
}
else
{
action();
}
}
#endregion
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender EventArgs e)
{
var timer = new System.Timers.Timer(1000);
timer.Elapsed += (s x) =>
{
DelegateAction(() =>
{
txtAll.Text = LogHelper.SetOnLog();
txtAll.Select(txtAll.TextLength 0);
txtAll.ScrollToCaret();
});
};
timer.Enabled = true;
timer.Start();
}
private void btnConn_Click(object sender EventArgs e)
{
if (client == null || !client.IsConnected)
ConnectServer();
}
///
/// 连接服务器
///
private async void ConnectServer()
{
client = new EasyClient();
client.Initialize(new MyReceiveFilter());
client.Connected += OnClientConnected;
client.NewPackageReceived += OnPagckageReceived;
client.Error += OnClientError;
client.Closed += OnClientClosed;
var webSocketUrl = System.Configuration.ConfigurationManager.AppSettings[“WebSocketURL“];
var webSocketPort = System.Configuration.ConfigurationManager.AppSettings[“WebSocketPort“];
var connected =
await client.ConnectAsync(new IPEndPoint(IPAddress.Parse(webSocketUrl) int.Parse(webSocketPort)));
}
private void OnClientClosed(object sender EventArgs e)
{
int attmpts = 5;
//if (timer1 != null)
//{
// timer1.Dispose();
//}
do
{
LogHelper.WriteLog(“连接已断开...“);
LogHelper.WriteLog(“等待5秒中后重新连接“);
Thread.Sleep(5000);
ConnectServer();
attmpts--;
} while (!client.IsConnected && attmpts > 0);
}
private void OnClientError(object sender ErrorEventArgs e)
{
LogHelper.WriteLog(“客户端错
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-03-20 16:21 SuperSocketClient\
目录 0 2018-03-20 10:59 SuperSocketClient\.vs\
目录 0 2018-05-17 08:32 SuperSocketClient\.vs\SuperSocketClient\
目录 0 2018-05-17 08:32 SuperSocketClient\.vs\SuperSocketClient\DesignTimeBuild\
文件 208 2018-05-17 08:32 SuperSocketClient\.vs\SuperSocketClient\DesignTimeBuild\.dtbcache
目录 0 2018-03-20 10:59 SuperSocketClient\.vs\SuperSocketClient\v15\
文件 95744 2018-07-05 15:08 SuperSocketClient\.vs\SuperSocketClient\v15\.suo
目录 0 2018-03-20 10:59 SuperSocketClient\.vs\SuperSocketClient\v15\Server\
目录 0 2018-05-14 17:18 SuperSocketClient\.vs\SuperSocketClient\v15\Server\sqlite3\
文件 0 2018-03-20 10:59 SuperSocketClient\.vs\SuperSocketClient\v15\Server\sqlite3\db.lock
文件 839680 2018-03-24 17:29 SuperSocketClient\.vs\SuperSocketClient\v15\Server\sqlite3\storage.ide
文件 32768 2018-06-29 08:40 SuperSocketClient\.vs\SuperSocketClient\v15\Server\sqlite3\storage.ide-shm
文件 1524432 2018-06-29 11:06 SuperSocketClient\.vs\SuperSocketClient\v15\Server\sqlite3\storage.ide-wal
目录 0 2018-06-26 16:36 SuperSocketClient\SuperSocketClient\
文件 666 2018-03-21 10:53 SuperSocketClient\SuperSocketClient\App.config
目录 0 2018-06-29 17:34 SuperSocketClient\SuperSocketClient\Appba
文件 5302 2018-06-29 08:49 SuperSocketClient\SuperSocketClient\Appba
文件 930 2018-03-22 14:07 SuperSocketClient\SuperSocketClient\Appba
文件 1577 2018-06-29 17:34 SuperSocketClient\SuperSocketClient\Appba
目录 0 2018-03-21 10:26 SuperSocketClient\SuperSocketClient\Common\
文件 1848 2018-03-21 09:04 SuperSocketClient\SuperSocketClient\Common\DataHelper.cs
文件 948 2018-03-21 10:26 SuperSocketClient\SuperSocketClient\Common\LogHelper.cs
文件 8967 2018-03-22 10:50 SuperSocketClient\SuperSocketClient\Form1.Designer.cs
文件 5543 2018-06-26 16:36 SuperSocketClient\SuperSocketClient\Form1.cs
文件 5817 2018-03-22 10:50 SuperSocketClient\SuperSocketClient\Form1.resx
文件 529 2018-03-20 10:59 SuperSocketClient\SuperSocketClient\Program.cs
目录 0 2018-03-20 10:59 SuperSocketClient\SuperSocketClient\Properties\
文件 1332 2018-03-20 10:59 SuperSocketClient\SuperSocketClient\Properties\AssemblyInfo.cs
文件 2847 2018-03-20 10:59 SuperSocketClient\SuperSocketClient\Properties\Resources.Designer.cs
文件 5612 2018-03-20 10:59 SuperSocketClient\SuperSocketClient\Properties\Resources.resx
文件 1104 2018-03-20 10:59 SuperSocketClient\SuperSocketClient\Properties\Settings.Designer.cs
............此处省略1576个文件信息
评论
共有 条评论