Exemplo n.º 1
0
        public Form1()
        {
            ReadBytesV2.ObjFormatType    = BuffFormatType.MsgPack;
            BufferFormatV2.ObjFormatType = BuffFormatType.MsgPack;

            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();
            }
        }
Exemplo n.º 2
0
        void main_UpFileClose(long key)
        {
            if (key == Key)
            {
                if (RConfig.ReadInt("IsCloseUP") != 1)
                {
                    IsClose           = true;
                    this.Text         = "上传完毕";
                    this.button1.Text = "完成";
                    this.Text        += "----完成";

                    BufferFormatV2 buffcheck = new BufferFormatV2((int)PackType.UpCheck);
                    buffcheck.AddItem(Key);
                    SocketManager.Send(buffcheck.Finish());
                }
                else
                {
                    IsClose           = true;
                    this.Text         = "上传完毕";
                    this.button1.Text = "完成";
                    this.Text        += "----完成";
                    BufferFormatV2 buffcheck = new BufferFormatV2((int)PackType.UpCheck);
                    buffcheck.AddItem(Key);
                    SocketManager.Send(buffcheck.Finish());
                    main.GotoDir();
                    this.Close();
                }
            }
        }
Exemplo n.º 3
0
        private void WinClient_Load(object sender, EventArgs e)
        {
            if (!TalkService.Connect(RConfig.ReadString("Host"), RConfig.ReadInt("Port")))
            {
                MessageBox.Show("无法连接服务器");
                Application.Exit();
                return;
            }

            LogAction.LogOut += LogAction_LogOut;


            //注册事件
            TalkService.ClientCall.MessageShowEvent    += MessageShow;
            TalkService.ClientCall.UpdateUserListEvent += UpdateUserList;



            LogOn tmp = new LogOn();

            tmp.ShowDialog();

            if (!tmp.IsLogOn)
            {
                Application.Exit();
            }
        }
Exemplo n.º 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开头的那个
            {
                while (true)
                {
                    Console.ReadLine();



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

                    for (int i = 0; i < 100; i++)
                    {
                        temp.guid.Add(Guid.NewGuid());
                    }
                    client.SendTo(BufferFormat.FormatFCA(temp));  //讲一个PPO对象发送出去


                    // Console.ReadLine();

                    BufferFormat buffmat = new BufferFormat(1001);
                    buffmat.AddItem(2);
                    buffmat.AddItem("通过组合数据包通讯,GUID is object");
                    buffmat.AddItem(Guid.NewGuid());

                    client.SendTo(buffmat.Finish()); //用组合数据包模拟PPO对象

                    // Console.ReadLine();

                    BufferFormat buffmat2 = new BufferFormat(1002);
                    buffmat2.AddItem(3);
                    buffmat2.AddItem("通过组合数据包通讯 all buff");
                    buffmat2.AddItem(Guid.NewGuid().ToString());
                    client.SendTo(buffmat2.Finish()); //用组合数据包模拟PPO对象 但GUID 是字符串类型
                }
            }
            else
            {
                Console.WriteLine("无法连接服务器");
            }

            Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            LogOut.Action += LogOut_Action;
            ZYNetClient client = new ZYNetClient();

            client.Connect(RConfig.ReadString("Host"), RConfig.ReadInt("ServicePort"));
            client.DataInput         += Client_ClientDataIn;
            client.ConnectToMe       += Client_ClientConnToMe;
            client.SessionDisconnect += Client_ClientDiscon;
            client.ServerDisconnect  += Client_ServerDisconnect;



            while (true)
            {
                byte[] data = Encoding.Default.GetBytes(Console.ReadLine());

                client.SendDataToALLClient(data);
            }
        }
Exemplo n.º 6
0
        private void WinClient_Load(object sender, EventArgs e)
        {
            if (!TalkService.Connect(RConfig.ReadString("Host"), RConfig.ReadInt("Port")))
            {
                MessageBox.Show("无法连接服务器");
                Application.Exit();
                return;
            }

            TalkService.Client.RegModule(this);
            LogAction.LogOut += LogAction_LogOut;
            LogOn tmp = new LogOn();

            tmp.ShowDialog();

            if (!tmp.IsLogOn)
            {
                Application.Exit();
            }
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
 public UserInfo()
 {
     BuffManger = new ZYNetRingBufferPool(RConfig.ReadInt("MaxBuffSize"));
 }