Exemplo n.º 1
0
 /// <summary>
 /// 启动按钮Tcp服务器
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnBegin_Click(object sender, EventArgs e)
 {
     try
     {
         server = TxStart.startServer(int.Parse(textBox_port.Text));
         server.AcceptString += new TxDelegate <IPEndPoint, string>(acceptString);
         server.StartEngine();
         this.btnBegin.Enabled = false;
     }
     catch (Exception Ex) { MessageBox.Show(Ex.Message); }
 }
Exemplo n.º 2
0
        /// <summary>
        ///     启动服务
        /// </summary>
        public void StartTCPServer()
        {
            try
            {
                Console.WriteLine("{0}", "读取socket配置信息.....");
                server = TxStart.startServer(BasePublic.ServerIP, BasePublic.ServerPort);
                Console.WriteLine("socket服务器{0}{1}", server.Ip, "启动中.....");
                server.AcceptString  += acceptString;
                server.AcceptByte    += acceptBytes;
                server.Connect       += connect;
                server.dateSuccess   += dateSuccess;
                server.Disconnection += disconnection;
                server.EngineClose   += engineClose;
                server.EngineLost    += engineLost;
                server.StartEngine();
                Console.WriteLine("socket服务器{0}{1}", server.Ip + ":" + server.Port, "启动成功.....");


                //非电量线程
                Thread thread = new Thread(SendNotEle);
                thread.Start();
                //用电量线程
                Thread threadEle = new Thread(SendEle);
                threadEle.Start();
                //能耗线程
                Thread threadEnergy = new Thread(SendEnergy);
                threadEnergy.Start();

                while (true)
                {
                    Console.WriteLine("....");
                    Thread.Sleep(1000);
                }
            }
            catch (Exception e)
            {
                var msg = string.Format("{0}  Socket<{1}:{2}>{3}  {4}",
                                        DateTime.Now.ToString(BasePublic.strTimeFormat), BasePublic.ServerIP, BasePublic.ServerPort, "启动失败",
                                        e.Message);
                Console.WriteLine(string.Format(msg));
                BasePublic.ExceptionDeal(BaseEnum.Socket, msg);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 启动按钮Tcp服务器
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         server = TxStart.startServer(int.Parse(textBox_port.Text));
         server.AcceptString  += new TxDelegate <IPEndPoint, string>(acceptString);
         server.Connect       += new TxDelegate <IPEndPoint>(connect);
         server.dateSuccess   += new TxDelegate <IPEndPoint>(dateSuccess);
         server.Disconnection += new TxDelegate <IPEndPoint, string>(disconnection);
         server.EngineClose   += new TxDelegate(engineClose);
         server.EngineLost    += new TxDelegate <string>(engineLost);
         //server.BufferSize=2048;
         //server.FileLog = "C:\\test.txt";
         server.StartEngine();
         this.button1.Enabled = false;
         this.button2.Enabled = true;
         this.button3.Enabled = true;
     }
     catch (Exception Ex) { MessageBox.Show(Ex.Message); }
 }
Exemplo n.º 4
0
        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("客户端启动异常.....");
            }
        }
Exemplo n.º 5
0
 public void InitTcpServer()
 {
     try
     {
         string serverPort = System.Configuration.ConfigurationManager.AppSettings["ServerPort"];
         server = TxStart.startServer(int.Parse(serverPort));
         server.AcceptString  += new TxDelegate <IPEndPoint, string>(acceptString);
         server.AcceptByte    += new TxDelegate <IPEndPoint, byte[]>(acceptBytes);
         server.Connect       += new TxDelegate <IPEndPoint>(connect);
         server.dateSuccess   += new TxDelegate <IPEndPoint>(dateSuccess);
         server.Disconnection += new TxDelegate <IPEndPoint, string>(disconnection);
         server.EngineClose   += new TxDelegate(engineClose);
         server.EngineLost    += new TxDelegate <string>(engineLost);
         server.StartEngine();
         Console.WriteLine($"服务器启动成功!!!!正在监听{serverPort}");
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 启动按钮Tcp服务器
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         server             = TxStart.startServer(int.Parse(textBox_port.Text));
         server.AcceptByte += new TxDelegate <IPEndPoint, byte[]>(acceptBytes);
         server.Connect    += new TxDelegate <IPEndPoint>(connect);
         //server.dateSuccess += new TxDelegate<IPEndPoint>(dateSuccess);
         server.Disconnection    += new TxDelegate <IPEndPoint, string>(disconnection);
         server.EngineClose      += new TxDelegate(engineClose);
         server.EngineLost       += new TxDelegate <string>(engineLost);
         server.PlayChess        += new TxDelegate <List <string>, char[, ], char, char>(playChess);
         server.LimitThinkSeconds = 300;
         server.StartEngine();
         this.button1.Enabled = false;
         chessInit(server.GetChessLayout());
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
     }
 }
Exemplo n.º 7
0
        public void startSocketListen()
        {
            try
            {
                txServer = TxStart.startServer(fkconfig.TcpPort);
                txServer.AcceptString  += TxServer_AcceptString;
                txServer.AcceptByte    += TxServer_AcceptByte;
                txServer.Connect       += TxServer_Connect;
                txServer.dateSuccess   += TxServer_dateSuccess;
                txServer.Disconnection += TxServer_Disconnection;
                txServer.EngineClose   += TxServer_EngineClose;
                txServer.EngineLost    += TxServer_EngineLost;
                txServer.BufferSize     = 100000;
                txServer.StartEngine();
                LogHelper.Log.Info("socket server start...");

                devSocketServer.Listen(200);
                devSocketServer.BeginAccept(new AsyncCallback(acceptCallback), devicePort);
            }
            catch (Exception Ex)
            {
                LogHelper.Log.Error("[ERROR] start socket server error ", Ex);
            }
        }