示例#1
0
        private void OnConnect(TCPSession session, SocketError e)
        {
            if (e != SocketError.Success)
            {
                Console.WriteLine(string.Format("{0} : ConnectResult {1} ", (session.UserData as SendInfor).Index, e.ToString()));
                return;
            }
            SendInfor infor = session.UserData as SendInfor;

            SendPack(session);
        }
示例#2
0
 public void Stop()
 {
     waiteEvent.WaitOne();
     foreach (var session in Sessions)
     {
         SendInfor infor = session.UserData as SendInfor;
         if (infor.SendNum < 100)
         {
             Console.WriteLine(string.Format("{0}, {1}, {2}", infor.Index, session.PackCount, infor.SendNum));
         }
     }
     client.Stop();
 }
示例#3
0
        private void SendPack(TCPSession session)
        {
            SendInfor infor = session.UserData as SendInfor;

            if (infor.SendNum > 100)
            {
                session.DisConnect();
                return;
            }
            StringNetPacket pongPacket = new StringNetPacket(1024);

            infor.SendNum++;
            session.SendPacket(pongPacket);
        }
示例#4
0
 public void Start()
 {
     times++;
     count = 0;
     for (int i = 0; i < MaxNum; ++i)
     {
         TCPSession session = new TCPSession();
         lock (Sessions)
         {
             Sessions.Add(session);
         }
         SendInfor infor = new SendInfor()
         {
             Index = i, times = times
         };
         session.UserData = infor;
         client.Connect("127.0.0.1", 12345, session);
         Thread.Sleep(2);
     }
 }
示例#5
0
 private void OnClose(object sender, TCPSocketToken token)
 {
     lock (Sessions)
     {
         var session = Sessions.FirstOrDefault(obj => obj.Token == token);
         if (session != null)
         {
             SendInfor infor = session.UserData as SendInfor;
             if (infor.SendNum < 100)
             {
                 Console.WriteLine(string.Format("On Close: {0}, {1}, {2}", infor.Index, session.PackCount, infor.SendNum));
             }
         }
         count++;
         Sessions.Remove(session);
         //Console.WriteLine(count);
         if (count == MaxNum)
         {
             waiteEvent.Set();
         }
     }
 }