private NetSimplifyServer netSimplify; // 同步网络访问的服务支持 private void NetSimplifyInitialization( ) { netSimplify = new NetSimplifyServer( ); // 实例化 netSimplify.ReceiveStringEvent += NetSimplify_ReceiveStringEvent; // 服务器接收字符串信息的时候,触发 netSimplify.LogNet = LogNet; // 设置日志 netSimplify.ServerStart(23457); // 启动服务 }
public void LogNetExample( ) { #region LogNetExample1 // 设备连接对象的日志 MelsecMcNet melsec = new MelsecMcNet("192.168.0.100", 6000); // 举例实现日志文件为单日志文件 melsec.LogNet = new HslCommunication.LogNet.LogNetSingle("D://123.txt"); #endregion #region LogNetExample2 // 一般服务器对象的 NetSimplifyServer simplifyServer = new NetSimplifyServer( ); simplifyServer.LogNet = new HslCommunication.LogNet.LogNetSingle("D://log.txt"); simplifyServer.ReceiveStringEvent += (HslCommunication.Core.Net.AppSession session, HslCommunication.NetHandle handle, string data) => { simplifyServer.SendMessage(session, handle, "Back:" + data); }; simplifyServer.ServerStart(45678); #endregion }
private void Start() { try { simplifyServer = new NetSimplifyServer( ); // 实例化 simplifyServer.Token = new Guid(textBox3.Text); // 设置令牌 simplifyServer.ReceiveStringEvent += SimplifyServer_ReceiveStringEvent; // 接收字符串的时候触发 simplifyServer.ReceiveStringArrayEvent += SimplifyServer_ReceiveStringArrayEvent; simplifyServer.LogNet = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath + @"\Logs\log.txt"); simplifyServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile; // 日志保存前先显示出来 simplifyServer.AddAccount("admin", "123456"); simplifyServer.AddAccount("hsl", "test"); simplifyServer.IsUseAccountCertificate = checkBox1.Checked; simplifyServer.ServerStart(int.Parse(textBox1.Text)); // 启动服务 userButton1.Enabled = false; timerSecond = new Timer( ); // 这个定时器的功能是每秒更新在线的客户端数量 timerSecond.Interval = 1000; timerSecond.Tick += TimerSecond_Tick; timerSecond.Start( ); } catch (Exception ex) { MessageBox.Show("创建失败:" + ex.Message); } }
public void TokenServerExample( ) { simplifyServer = new NetSimplifyServer( ); simplifyServer.Token = new Guid("787f9607-dd7a-4ba7-9f98-769d24de05df"); simplifyServer.ReceiveStringEvent += SimplifyServer_ReceiveStringEvent; simplifyServer.ServerStart(12345); }
/// <summary> /// 启动服务器的后台存储 /// </summary> /// <param name="port"></param> public void ServerStart(int port) { simplifyServer = new NetSimplifyServer(); simplifyServer.Token = Token; simplifyServer.LogNet = LogNet; simplifyServer.ReceiveStringEvent += SimplifyServer_ReceiveStringEvent; simplifyServer.ServerStart(port); for (var i = 0; i < deviceCores.Count; i++) { deviceCores[i].StartRead(); } }
private void Start() { try { simplifyServer = new NetSimplifyServer( ); simplifyServer.Token = new Guid(textBox3.Text); simplifyServer.ReceiveStringEvent += SimplifyServer_ReceiveStringEvent; simplifyServer.LogNet = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath + @"\Logs\log.txt"); simplifyServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile; simplifyServer.ServerStart(int.Parse(textBox1.Text)); } catch (Exception ex) { MessageBox.Show("创建失败:" + ex.Message); } }
private void Start() { try { simplifyServer = new NetSimplifyServer( ); simplifyServer.Token = new Guid(textBox3.Text); simplifyServer.ReceiveStringEvent += SimplifyServer_ReceiveStringEvent; simplifyServer.LogNet = new HslCommunication.LogNet.LogNetSingle(Application.StartupPath + @"\Logs\log.txt"); simplifyServer.LogNet.BeforeSaveToFile += LogNet_BeforeSaveToFile; simplifyServer.ServerStart(int.Parse(textBox1.Text)); userButton1.Enabled = false; timerSecond = new Timer( ); timerSecond.Interval = 1000; timerSecond.Tick += TimerSecond_Tick; timerSecond.Start( ); } catch (Exception ex) { MessageBox.Show("创建失败:" + ex.Message); } }