Esempio n. 1
0
        public void SendData(byte[] data)
        {
            Client_Data tmp = new Client_Data();

            tmp.Data = data;
            Sock.BeginSendData(BufferFormat.FormatFCA(tmp));
        }
Esempio n. 2
0
        /// <summary>
        /// 连接到服务器
        /// </summary>
        /// <param name="host"></param>
        /// <param name="port"></param>
        public bool Connect(string host, int port)
        {
            if (MainClient != null)
            {
                throw new ObjectDisposedException("MainClient", "连接已经初始化,无法再连接,请重新 new ZYNetClient");
            }

            MainClient               = new SocketClient();
            MainClient.BinaryInput  += Client_BinaryInput;
            MainClient.MessageInput += Client_MessageInput;

            if (MainClient.Connect(host, port))
            {
                MainClient.StartRead();

                LLOG("成功连接服务器", ActionType.ServerConn);
                RegHost = host;

                string localip = ((IPEndPoint)(MainClient.Sock.LocalEndPoint)).Address.ToString(); //获取本地局域网IP地址

                RegSession session = new RegSession()
                {
                    LocalHost = localip,
                    Group     = Group
                };

                SendToServer(BufferFormat.FormatFCA(session));

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        public void SendDataToServer(byte[] data)
        {
            ProxyData tmp = new ProxyData();

            tmp.Source = this.Id;
            tmp.Data   = data;
            tmp.Ids    = new List <long>();
            tmp.Ids.Add(0);
            MainClient.BeginSendData(BufferFormat.FormatFCA(tmp));
        }
Esempio n. 4
0
        /// <summary>
        /// 获取所有的用户
        /// </summary>
        public void GetAllUserSession()
        {
            GetAllSession tmp = new GetAllSession()
            {
                UserIds   = new List <long>(),
                IsSuccess = false
            };

            SendToServer(BufferFormat.FormatFCA(tmp));
        }
Esempio n. 5
0
        /// <summary>
        /// 发送数据包给所有人,不包括服务器
        /// </summary>
        /// <param name="data"></param>
        public void SendDataToALLClient(byte[] data)
        {
            var list = GetNotConnectSession();

            if (list.Count > 0)
            {
                ProxyData tmp = new ProxyData();
                tmp.Source = this.Id;
                tmp.Data   = data;
                tmp.Ids    = list;
                MainClient.BeginSendData(BufferFormat.FormatFCA(tmp));
            }

            foreach (var item in GetConnectSession())
            {
                item.Client.SendData(data);
            }
        }
Esempio n. 6
0
        public void SendData(long Id, byte[] data)
        {
            if (ConnUserList.ContainsKey(Id))
            {
                var session = ConnUserList[Id];

                if (session.IsConnect && session.Client != null)
                {
                    session.Client.SendData(data);
                }
                else
                {
                    ProxyData tmp = new ProxyData();
                    tmp.Source = this.Id;
                    tmp.Data   = data;
                    tmp.Ids    = new List <long>();
                    tmp.Ids.Add(Id);
                    MainClient.BeginSendData(BufferFormat.FormatFCA(tmp));
                }
            }
        }