Example #1
0
        static void Main()
        {
            //string fileName = "a/c/dd.txt";
            //string dirStr = new FileInfo(fileName).FullName;
            //DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(fileName));
            //Process thisProcess = Process.GetCurrentProcess();
            NetIOCPClient.Log.Logs.AddConsoleAppender();

            Net_Client nc = new Net_Client();
            //121.40.174.130,12588
            //121.40.189.10,12588
            string ip   = "121.40.189.10";
            int    port = 12588;

            //
            nc.OnConnectBegin  += nc_OnConnectBegin;
            nc.OnConncetEnd    += nc_OnConncetEnd;
            nc.OnDisconnect    += nc_OnDisconnect;
            nc.OnRecvData      += nc_OnRecvData;
            nc.OnRecvDataBytes += nc_OnRecvDataBytes;
            nc.OnRecvError     += nc_OnRecvError;
            nc.OnSend          += nc_OnSend;
            nc.OnSendError     += nc_OnSendError;
            //
            //login
            byte[] login = createLoginPacket();
            Console.WriteLine(NetIOCPClient.Util.Utility.ToHex(0, login, 0, login.Length));

            nc.BeginConnect(ip, port);
            //
            m_WaitObj.WaitOne(1000 * 10);

            nc.Send(login, 0, login.Length);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            nc.StartHeatbeat();
            while (true)
            {
                if (nc.IsConnected)
                {
                    nc.ProcessSendAndRecivedPackets();
                    if (sw.ElapsedMilliseconds > 1000 * 60)
                    {
                        Console.WriteLine("60秒接收数据:" + nc.ReceivedBytes.ToString());
                        //
                        Console.WriteLine(nc.GetNetworkInfo());
                        sw.Reset();
                        sw.Start();
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(1000 * 5);
                    System.Threading.Monitor.Enter(_syncObj);
                    nc.BeginConnect(ip, port);
                    m_WaitObj.WaitOne(1000 * 10);
                    nc.Send(login, 0, login.Length);
                    nc.StartHeatbeat();
                }
                System.Threading.Thread.Sleep(10);
            }
        }
Example #2
0
        static void Main()
        {
            //string fileName = "a/c/dd.txt";
            //string dirStr = new FileInfo(fileName).FullName;
            //DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(fileName));
            //Process thisProcess = Process.GetCurrentProcess();
            NetIOCPClient.Log.Logs.AddConsoleAppender();

            Net_Client nc = new Net_Client();
            //121.40.174.130,12588
            //121.40.189.10,12588
            string ip = "121.40.189.10";
            int port=12588;
            //
            nc.OnConnectBegin += nc_OnConnectBegin;
            nc.OnConncetEnd += nc_OnConncetEnd;
            nc.OnDisconnect += nc_OnDisconnect;
            nc.OnRecvData += nc_OnRecvData;
            nc.OnRecvDataBytes += nc_OnRecvDataBytes;
            nc.OnRecvError += nc_OnRecvError;
            nc.OnSend += nc_OnSend;
            nc.OnSendError += nc_OnSendError;
            //
            //login
            byte[] login=createLoginPacket();
            Console.WriteLine(NetIOCPClient.Util.Utility.ToHex(0, login, 0, login.Length));

            nc.BeginConnect(ip,port);
            //
            m_WaitObj.WaitOne(1000 * 10);

            nc.Send(login,0,login.Length);
            Stopwatch sw = new Stopwatch();
            sw.Start();
            nc.StartHeatbeat();
            while (true) {
                if (nc.IsConnected) {
                    nc.ProcessSendAndRecivedPackets();
                    if (sw.ElapsedMilliseconds > 1000 * 60) {
                        Console.WriteLine("60秒接收数据:" + nc.ReceivedBytes.ToString());
                        //
                        Console.WriteLine(nc.GetNetworkInfo());
                        sw.Reset();
                        sw.Start();
                    }
                }
                else {
                      System.Threading.Thread.Sleep(1000*5);
                      System.Threading.Monitor.Enter(_syncObj);
                      nc.BeginConnect(ip, port);
                      m_WaitObj.WaitOne(1000 * 10);
                      nc.Send(login, 0, login.Length);
                      nc.StartHeatbeat();
                }
                System.Threading.Thread.Sleep(10);

            }
        }