Exemple #1
0
 private void RecvData(object sender, NetEventArgs e)
 {
     try
     {
         if (DebugShow)
         {
             rtbe1.SetText(string.Format("from:{0} recv data:[{1}]", e.Client, e.Client.Datagram.Replace("\r\n", "")), true);
         }
         SocketStatus.Text      = e.Client.ID.ToString();
         SocketStatusLabel.Text = e.Client.Datagram.Replace("\r\n", "");
         UpdItemB(e.Client.ID.ToString(), String.Empty);
         UpdItem(e.Client.ID.ToString(), e.Client.Datagram.ToString());
         //if(DebugShow) rtbe1.SetText(Game.Network.Coder.ShowHexString(e.Client.Datagram), true);
         FunctionParser fp           = new FunctionParser(e);
         String         ReturnString = fp.ReturnFunction();
         fp.Dispose();
         //String ReturnString = LoginParser(e);
         //ReturnString += Convert.ToChar(4).ToString();
         TcpSvr svr = (TcpSvr)sender;
         //测试把收到的数据返回给客户端
         svr.Send(e.Client, ReturnString);
         if (DebugShow)
         {
             rtbe1.SetText(string.Format("from:{0} send data:[{1}]", e.Client, ReturnString), true);
         }
         //throw new NotImplementedException();
         SessionCount.Text = String.Format("Current count of Client is {0}/{1}", ts.SessionCount, ts.Capacity);
         UpdItemB(e.Client.ID.ToString(), ReturnString);
     }
     catch (Exception ex)
     {
         SocketStatusLabel.Text = ex.Message;
         String Datagram = "{\"methodName\":\"Error\",\"paramObject\":{\"Cord\":\"9999\",\"text\":\"";
         Datagram += ex.Message;
         Datagram += "\"}}";
         TcpSvr svr = (TcpSvr)sender;
         //测试把收到的数据返回给客户端
         svr.Send(e.Client, Datagram);
     }
 }