Пример #1
0
        public Form1()
        {
            InitializeComponent();
            server = new ZYSocketSuper();

            server.BinaryInput  = new BinaryInputHandler(BinaryInputHandler);   //设置输入代理
            server.Connetions   = new ConnectionFilter(ConnectionFilter);       //设置连接代理
            server.MessageInput = new MessageInputHandler(MessageInputHandler); //设置 客户端断开
        }
Пример #2
0
        public void ReadDataSet(ZYSocketSuper server, ReadBytes read, SocketAsyncEventArgs socketAsync)
        {
            ReadDataSet rd;

            if (read.ReadObject <ReadDataSet>(out rd)) //读取请求DATASET 数据包
            {
                if (rd != null)
                {
                    rd.Data = new List <DataValue>();

                    rd.TableName = "table1";
                    rd.Data.Add(new DataValue()
                    {
                        V1 = "第1个",
                        V2 = "第2个",
                        V3 = "第3个",
                        V4 = "第4个",
                        V5 = "第5个"
                    });

                    rd.Data.Add(new DataValue()
                    {
                        V1 = "第6个",
                        V2 = "第7个",
                        V3 = "第8个",
                        V4 = "第9个",
                        V5 = "第10个"
                    });

                    rd.Data.Add(new DataValue()
                    {
                        V1 = "第11个",
                        V2 = "第12个",
                        V3 = "第13个",
                        V4 = "第14个",
                        V5 = "第15个"
                    });


                    rd.Data.Add(new DataValue()
                    {
                        V1 = "第16个",
                        V2 = "第17个",
                        V3 = "第18个",
                        V4 = "第19个",
                        V5 = "第20个"
                    });

                    server.SendData(socketAsync.AcceptSocket, BufferFormat.FormatFCA(rd)); //发送

                    Console.WriteLine((socketAsync.UserToken as User.UserInfo).UserName + " 读取了" + rd.TableName);
                }
            }
        }
Пример #3
0
        public Form1()
        {
            InitializeComponent();

            ReadBytesV2.ObjFormatType    = BuffFormatType.protobuf;
            BufferFormatV2.ObjFormatType = BuffFormatType.protobuf;


            server              = new ZYSocketSuper();
            server.BinaryInput  = new BinaryInputHandler(BinaryInputHandler);   //设置输入代理
            server.Connetions   = new ConnectionFilter(ConnectionFilter);       //设置连接代理
            server.MessageInput = new MessageInputHandler(MessageInputHandler); //设置 客户端断开
        }
Пример #4
0
        public void Ping(ZYSocketSuper server, ReadBytes read, SocketAsyncEventArgs socketAsync)
        {
            Ping pdata;

            if (read.ReadObject <Ping>(out pdata)) //读取PING 数据包
            {
                if (pdata != null)
                {
                    pdata.ServerReviceTime = DateTime.Now;                                    //设置服务器时间
                    server.SendData(socketAsync.AcceptSocket, BufferFormat.FormatFCA(pdata)); //发送返回
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            MainServer              = new ZYSocketSuper(Config.Default.ServerIP, Config.Default.MServerPort, Config.Default.MaxConCount, 1024);
            MainServer.BinaryInput  = new BinaryInputHandler(MainDataIn);
            MainServer.Connetions   = new ConnectionFilter(MainConnetion);
            MainServer.MessageInput = new MessageInputHandler(MainExpection);

            IpServer              = new ZYSocketSuper(Config.Default.ServerIP, Config.Default.RegServerPort, Config.Default.MaxConCount, 1024);
            IpServer.BinaryInput  = new BinaryInputHandler(IpDataIn);
            IpServer.Connetions   = new ConnectionFilter(IpConnetion);
            IpServer.MessageInput = new MessageInputHandler(IpExpection);

            IpServer.Start();
            MainServer.Start();


            Console.ReadLine();
        }
Пример #6
0
        public void LogOn(ZYSocketSuper server, ReadBytes read, SocketAsyncEventArgs socketAsync)
        {
            Login p;

            if (read.ReadObject <Login>(out p))
            {
                if (p != null)
                {
                    if (User.UserManger.GetUserDataManger().CheckUser(p.UserName, p.PassWord)) //检查用户名密码是否正确
                    {
                        User.UserInfo user = new User.UserInfo()                               //建立一个新的用户对象 并且初始化 用户名
                        {
                            UserName = p.UserName
                        };

                        socketAsync.UserToken = user; //设置USERTOKEN

                        Message err = new Message()   //初始化MESSAGE数据包类
                        {
                            Type       = 2,
                            MessageStr = "登入成功"
                        };

                        server.SendData(socketAsync.AcceptSocket, BufferFormat.FormatFCA(err)); //发送此类

                        Console.WriteLine(user.UserName + " 登入");
                    }
                    else
                    {
                        Message err = new Message() //初始化用户名密码错误数据包
                        {
                            Type       = 1,
                            MessageStr = "用户名或密码错误"
                        };

                        server.SendData(socketAsync.AcceptSocket, BufferFormat.FormatFCA(err));
                    }
                }
            }
        }
Пример #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;
        }
Пример #8
0
 public RPCServer(string host, int port, int maxconnectcout, int maxbuffersize)
 {
     Server = new ZYSocketSuper(host, port, maxconnectcout, maxbuffersize);
     Init();
 }
Пример #9
0
 public RPCServer()
 {
     Server = new ZYSocketSuper();
     Init();
 }
Пример #10
0
 public RPCServer()
 {
     Server      = new ZYSocketSuper();
     MaxBuffsize = 1024 * 1024 * 2; //2M
     Init();
 }
Пример #11
0
 public CloudServer(string host, int port, int maxconnectcout, int maxbuffersize, int maxPackSize)
 {
     Server      = new ZYSocketSuper(host, port, maxconnectcout, maxbuffersize);
     MaxBuffsize = maxPackSize;
     Init();
 }
Пример #12
0
 public CloudServer(int maxPackSize)
 {
     Server      = new ZYSocketSuper();
     MaxBuffsize = maxPackSize;
     Init();
 }