Exemple #1
0
        /// <summary>
        /// 启动
        /// </summary>
        public void Start()
        {
            if (IsRun)
            {
                LLOG("Service Is Start...", EventLogType.INFO);
                return;
            }

            BufferFormat.ObjFormatType = BuffFormatType.protobuf;
            ReadBytes.ObjFormatType    = BuffFormatType.protobuf;

            ServicePackHander.GetInstance().Loading();

            SessionDiy = new ConcurrentDictionary <long, ZYNetSession>();

            Service                   = new ZYSocketSuper(RConfig.ReadString("Host"), RConfig.ReadInt("ServicePort"), RConfig.ReadInt("MaxConnectCount"), 4096); //初始化
            Service.Connetions        = new ConnectionFilter(Service_Connection);                                                                                //注册连接回调
            Service.BinaryOffsetInput = new BinaryInputOffsetHandler(Service_BinaryInput);                                                                       //注册输入包输入回调
            Service.MessageInput      = new MessageInputHandler(Service_UserDisconnect);                                                                         //注册用户断开回调
            Service.IsOffsetInput     = true;

            RegService              = new ZYSocketSuper(RConfig.ReadString("Host"), RConfig.ReadInt("RegPort"), RConfig.ReadInt("MaxConnectCount"), 1024); //初始化注册端口
            RegService.Connetions   = new ConnectionFilter(RegServer_Connection);                                                                          //注册连接回调
            RegService.BinaryInput  = new BinaryInputHandler(RegServer_BinaryInput);                                                                       //注册输入包输入回调
            RegService.MessageInput = new MessageInputHandler(RegServer_UserDisconnect);                                                                   //注册用户断开回调

            Service.Start();
            RegService.Start();

            RegPort         = RConfig.ReadInt("RegPort");
            BufferMaxLength = RConfig.ReadInt("BufferLength");


            LLOG("Service StartIng...", EventLogType.INFO);



            IsRun = true;
        }
Exemple #2
0
        public Form1()
        {
            if (SocketManager.client.ConnectionTo(RConfig.ReadString("Host"), RConfig.ReadInt("Port"))) //连接到服务器
            {
                logon = new LogOn();

                logon.ShowDialog(); //显示登入界面

                if (!logon.Logins)  //如果登入界面关闭那么检查是否登入成功如果没有登入成功 则关闭程序
                {
                    Close();
                }

                SocketManager.Disconnection += new ExceptionDisconnection(client_Disconnection); //注册断开事件
                SocketManager.DataInput     += new DataOn(client_DataOn);                        //注册数据包输入事件
                InitializeComponent();
            }
            else
            {
                MessageBox.Show("无法连接服务器"); //无法连接 提示 并关闭
                Close();
            }
        }
Exemple #3
0
 public TriplePCAComponent(ComponentLogger log)
     : base(log)
 {
     _config       = new RConfig();
     Configuration = _config;
 }
Exemple #4
0
        static void Main(string[] args)
        {
            client.DataOn += new DataOn(client_DataOn);                                   //数据包进入事件

            client.Disconnection += new ExceptionDisconnection(client_Disconnection);     //数据包断开事件

            if (client.ConnectionTo(RConfig.ReadString("Host"), RConfig.ReadInt("Port"))) //使用同步连接到服务器,一步就用Begin开头的那个
            {
                int i = 0;
                while (true)
                {
                    Console.ReadLine();



                    testClass.PPo temp = new testClass.PPo();
                    temp.Id       = i;
                    temp.Message  = "通过对象通讯";
                    temp.guidList = new List <Guid>();

                    i++;

                    for (int x = 0; x <= i; x++)
                    {
                        temp.guidList.Add(Guid.NewGuid());
                    }



                    client.SendTo(new byte[] { 1, 2, 3, 4, 5, 6 });

                    client.SendTo(BufferFormatV2.FormatFCA(temp));  //讲一个PPO对象发送出去



                    BufferFormat buffmat = new BufferFormatV2(1001);
                    buffmat.AddItem(i);
                    buffmat.AddItem("通过组合数据包通讯,GUID is object");
                    buffmat.AddItem(Guid.NewGuid());
                    client.SendTo(buffmat.Finish()); //用组合数据包模拟PPO对象



                    BufferFormat buffmat2 = new BufferFormatV2(1002);
                    buffmat2.AddItem(i);
                    buffmat2.AddItem("通过组合数据包通讯 all buff");
                    buffmat2.AddItem(Guid.NewGuid().ToString());
                    client.SendTo(buffmat2.Finish()); //用组合数据包模拟PPO对象 但GUID 是字符串类型



                    List <testClass.PPo2> tmplist = new List <testClass.PPo2>();


                    for (int l = 0; l < 30; l++)
                    {
                        testClass.PPo2 ver2 = new testClass.PPo2();
                        ver2.Id      = i;
                        ver2.Message = "列表复用";
                        ver2.PPoList = new List <testClass.PPo>();

                        for (int j = 0; j < 10; j++)
                        {
                            testClass.PPo temp2 = new testClass.PPo();
                            temp2.Id       = i;
                            temp2.Message  = "通过对象通讯";
                            temp2.guidList = new List <Guid>();

                            for (int x = 0; x <= 20; x++)
                            {
                                temp2.guidList.Add(Guid.NewGuid());
                            }

                            ver2.PPoList.Add(temp2);
                        }

                        tmplist.Add(ver2);
                    }

                    BufferFormatV2 buffer = new BufferFormatV2(2000);
                    buffer.AddItem(tmplist);


                    client.SendTo(buffer.Finish());
                }
            }
            else
            {
                Console.WriteLine("无法连接服务器");
            }

            Console.ReadLine();
        }
Exemple #5
0
 public UserInfo()
 {
     BuffManger = new ZYNetRingBufferPool(RConfig.ReadInt("MaxBuffSize"));
 }