/// <summary> /// 连接192.168.1.193 /// </summary> private void init3() { string ip = "127.0.0.1"; try { var task3 = Task.Run(() => { TxClient1 = TxStart.startClient(ip, port3); TxClient1.AcceptString += new TxDelegate <IPEndPoint, string>(accptString); //当收到文本数据的时候 TxClient1.dateSuccess += new TxDelegate <IPEndPoint>(sendSuccess); //当对方已经成功收到我数据的时候 TxClient1.EngineClose += new TxDelegate(engineClose); //当客户端引擎完全关闭释放资源的时候 TxClient1.EngineLost += new TxDelegate <string>(engineLost); //当客户端非正常原因断开的时候 TxClient1.ReconnectionStart += new TxDelegate(reconnectionStart); //当自动重连开始的时候 TxClient1.StartResult += new TxDelegate <bool, string>(startResult); //当登录完成的时候 //TxClient.BufferSize = 12048;//这里大小自己设置,默认为1KB,也就是1024个字节 TxClient1.StartEngine(); }); } catch (Exception ex) { Logger.Log($"连接{ip}异常{ex.Message}", LogLevel.Error); } }
/// <summary> /// 连接192.168.1.191 /// </summary> private void init1() { string ip = "127.0.0.1"; try { var task1 = Task.Run(() => { TxClient = TxStart.startClient(ip, port1); TxClient.AcceptString += new TxDelegate <IPEndPoint, string>(accptString);//当收到文本数据的时候 //TxClient.AcceptByte += new TxDelegate<IPEndPoint, byte[]>(accptByte);//当收到文本数据的时候 TxClient.dateSuccess += new TxDelegate <IPEndPoint>(sendSuccess); //当对方已经成功收到我数据的时候 TxClient.EngineClose += new TxDelegate(engineClose); //当客户端引擎完全关闭释放资源的时候 TxClient.EngineLost += new TxDelegate <string>(engineLost); //当客户端非正常原因断开的时候 TxClient.ReconnectionStart += new TxDelegate(reconnectionStart); //当自动重连开始的时候 TxClient.StartResult += new TxDelegate <bool, string>(startResult); //当登录完成的时候 //TxClient.BufferSize = 12048;//这里大小自己设置,默认为1KB,也就是1024个字节 TxClient.StartEngine(); }); //处理任务数据 Task.Run(async() => { while (true) { await Task.Delay(200); var res = ProcessingTask(); if (res.Success) { //数据组合后,发送数据 string sql = $"update print_Middle set commintFlag={(int)PrintCommintFlag.已发送} where id ={res.Data.PrintID}"; AppSession.Dal.ExcuteCommonSqlForInsertOrUpdate(sql); Logger.Log($"发送数据至IP{ip}:{res.Data.DataSplitting}", LogLevel.Info); TxClient.sendMessage(res.Data.DataSplitting); } else { Logger.Log($"异常:发送数据至IP{ip}:{res.Data.DataSplitting}", LogLevel.Error); } } }); } catch (Exception Ex) { Logger.Log($"连接{ip}异常{Ex.Message}", LogLevel.Exception); } }
private void button2_Click(object sender, EventArgs e) { try { TxClient = TxStart.startClient(textBox2.Text, int.Parse(textBox3.Text)); TxClient.AcceptString += new TxDelegate <IPEndPoint, string>(accptString); //当收到文本数据的时候 TxClient.dateSuccess += new TxDelegate <IPEndPoint>(sendSuccess); //当对方已经成功收到我数据的时候 TxClient.EngineClose += new TxDelegate(engineClose); //当客户端引擎完全关闭释放资源的时候 TxClient.EngineLost += new TxDelegate <string>(engineLost); //当客户端非正常原因断开的时候 TxClient.ReconnectionStart += new TxDelegate(reconnectionStart); //当自动重连开始的时候 TxClient.StartResult += new TxDelegate <bool, string>(startResult); //当登录完成的时候 //TxClient.BufferSize = 12048;//这里大小自己设置,默认为1KB,也就是1024个字节 TxClient.StartEngine(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public void StartListen(string host, int port) { try { TxClient = TxStart.startClient(host, port); TxClient.AcceptString += new TxDelegate <IPEndPoint, string>(acceptData); //接受数据回调 TxClient.dateSuccess += new TxDelegate <IPEndPoint>(sendDataSuccess); //对方成功接受数据回调 TxClient.EngineClose += new TxDelegate(clientClose); //用户端引擎关闭回调 TxClient.EngineLost += new TxDelegate <string>(clientLost); //用户端非正常关闭回调 TxClient.ReconnectionStart += new TxDelegate(reconnectStart); //当自动重连开始的回调 TxClient.StartResult += new TxDelegate <bool, string>(connectResult); //登录完成回调 //TxClient.Data_Max = 2048; 设置缓存大小 TxClient.StartEngine(); } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void connectBtn_Click(object sender, EventArgs e) { try { TxClient = TxStart.startClient(textBox2.Text, int.Parse(textBox3.Text)); TxClient.dateSuccess += new TxDelegate <IPEndPoint>(sendSuccess); //当对方已经成功收到我数据的时候 TxClient.EngineClose += new TxDelegate(engineClose); //当客户端引擎完全关闭释放资源的时候 TxClient.EngineLost += new TxDelegate <string>(engineLost); //当客户端非正常原因断开的时候 TxClient.ReconnectionStart += new TxDelegate(reconnectionStart); //当自动重连开始的时候 TxClient.StartResult += new TxDelegate <bool, string>(startResult); //当登录完成的时候 TxClient.ShowAbleMove += new TxDelegate <List <List <string> > >(showAbleMove); //当轮到行走时,显示所有可行解 TxClient.StartEngine(); notify.Text = "* 连上了,等一下AI..."; } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public void Start() { try { Console.WriteLine("{0}", "读取配置信息....."); TxClientServer = TxStart.startServer(ClientServerIP, ClientServerPort); Console.WriteLine("服务器{0}{1}", TxClientServer.Ip, "启动中....."); TxClientServer.AcceptString += acceptString_Server; TxClientServer.AcceptByte += acceptBytes_Server; TxClientServer.Connect += connect_Server; TxClientServer.dateSuccess += dateSuccess_Server; TxClientServer.Disconnection += disconnection_Server; TxClientServer.EngineClose += engineClose_Server; TxClientServer.EngineLost += engineLost_Server; //server.BufferSize=12048; //server.FileLog = "C:\\test.txt"; TxClientServer.StartEngine(); Console.WriteLine("服务器{0}{1}", TxClientServer.Ip + ":" + TxClientServer.Port, "启动成功....."); Console.WriteLine("创建客户端....."); TxClient = TxStart.startClient(ClientIP, ClientPort); Console.WriteLine("客户端创建成功....."); TxClient.AcceptString += accptString_Client; //当收到文本数据的时候 TxClient.dateSuccess += sendSuccess_Client; //当对方已经成功收到我数据的时候 TxClient.EngineClose += engineClose_Client; //当客户端引擎完全关闭释放资源的时候 TxClient.EngineLost += engineLost_Client; //当客户端非正常原因断开的时候 TxClient.ReconnectionStart += reconnectionStart_Client; //当自动重连开始的时候 TxClient.StartResult += startResult_Client; //当登录完成的时候 //TxClient.BufferSize = 12048;//这里大小自己设置,默认为1KB,也就是1024个字节 Console.WriteLine("客户端启动....."); TxClient.StartEngine(); Console.WriteLine("客户端{0}{1}", TxClient.Ip + ":" + TxClient.Port, "启动成功....."); Console.ReadLine(); } catch (Exception Ex) { Console.WriteLine("客户端启动异常....."); } }
public void InitTcpClient() { try { string serverPort = System.Configuration.ConfigurationManager.AppSettings["ServerPort"]; string serverIP = System.Configuration.ConfigurationManager.AppSettings["ServerIP"]; TxClient = TxStart.startClient(serverIP, int.Parse(serverPort)); TxClient.AcceptString += new TxDelegate <IPEndPoint, string>(accptString); //当收到文本数据的时候 TxClient.dateSuccess += new TxDelegate <IPEndPoint>(sendSuccess); //当对方已经成功收到我数据的时候 TxClient.EngineClose += new TxDelegate(engineClose); //当客户端引擎完全关闭释放资源的时候 TxClient.EngineLost += new TxDelegate <string>(engineLost); //当客户端非正常原因断开的时候 TxClient.ReconnectionStart += new TxDelegate(reconnectionStart); //当自动重连开始的时候 TxClient.StartResult += new TxDelegate <bool, string>(startResult); //当登录完成的时候 //TxClient.BufferSize = 12048;//这里大小自己设置,默认为1KB,也就是1024个字节 TxClient.StartEngine(); TxClient.ReconnectMax = 100; SendInfo(); } catch (Exception) { throw; } }