Beispiel #1
0
        protected override void OnReceived(byte[] data)
        {
            Actived = DateTime.Now;
            base.UserToken.Unpacker.Unpack(data, (msg) =>
            {
                switch (msg.Type)
                {
                case (byte)TcpP2pType.Heart:
                    break;

                case (byte)TcpP2pType.PublicNatInfoRequest:
                    break;

                case (byte)TcpP2pType.PublicNatInfoResponse:
                    _me = SerializeHelper.ByteDeserialize <NatInfo>(msg.Content);
                    OnPublicNatInfoResponse.Invoke(_me);
                    break;

                case (byte)TcpP2pType.Message:
                    OnMessage?.Invoke(msg);
                    break;

                case (byte)TcpP2pType.P2PSResponse:
                    OnReceiveP2PTask?.Invoke(SerializeHelper.ByteDeserialize <NatInfo>(msg.Content));
                    break;

                case (byte)TcpP2pType.P2PResponse:
                    OnP2PSucess?.Invoke(_me);
                    break;

                case (byte)TcpP2pType.Logout:
                case (byte)TcpP2pType.Close:
                default:
                    SendClose();
                    base.Disconnect();
                    break;
                }
            }, null, null);
        }
Beispiel #2
0
        protected override void OnReceived(byte[] data)
        {
            base.UserToken.Coder.Pack(data, null, (msg) =>
            {
                switch (msg.Type)
                {
                case (byte)HolePunchingType.Heart:
                    break;

                case (byte)HolePunchingType.Login:
                    break;

                case (byte)HolePunchingType.LoginResponse:
                    _remoteList = SerializeHelper.ByteDeserialize <List <string> >(msg.Content);
                    break;

                case (byte)HolePunchingType.Message:
                    OnMessage?.Invoke(msg);
                    break;

                case (byte)HolePunchingType.P2PSResponse:
                    HolePunching(msg);
                    break;

                case (byte)HolePunchingType.P2PResponse:
                    OnP2PSucess?.Invoke(_peerBAddress);
                    break;

                case (byte)HolePunchingType.Logout:
                case (byte)HolePunchingType.Close:
                default:
                    SendLogout();
                    base.Disconnect();
                    break;
                }
            }, null);
        }
 /// <summary>
 ///     ioc所需初始化方法
 /// </summary>
 /// <param name="redisHelper"></param>
 public void CreateInstance(IRedisHelper redisHelper)
 {
     _redisHelper = SerializeHelper.ByteDeserialize <IRedisHelper>(SerializeHelper.ByteSerialize(redisHelper));
 }
        /// <summary>
        /// 接收远程桌面的图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="file"></param>
        /// <param name="type">1 整图 2 切片</param>
        private void _mClient_OnFile(object sender, byte[] file, string type)
        {
            try
            {
                if (file.Length != 0 && file != null)
                {
                    var deDates = CompressHelper.Decompress(file);
                    if (type == "1")
                    {
                        var datas = deDates;

                        this.InvokeAction(() =>
                        {
                            try
                            {
                                this.pictureBox1.Image = ImageHelper.ToImage(datas);
                                lastBitmap             = (Bitmap)ImageHelper.ToImage(datas);
                                ImageProportion        = (float)this.pictureBox1.Image.Width / (float)this.pictureBox1.Image.Height;
                                this.Invoke(new Action(() =>
                                {
                                    this.pictureBox1.Refresh();
                                }));
                            }
                            catch { }
                        });
                    }
                    if (type == "2")
                    {
                        Dictionary <Rectangle, Bitmap> dic = SerializeHelper.ByteDeserialize <Dictionary <Rectangle, Bitmap> >(deDates);
                        if (dic != null && dic.Count > 0)
                        {
                            foreach (var item in dic)
                            {
                                Bitmap bm = new Bitmap(item.Key.Width, item.Key.Height);
                                using (Graphics g = Graphics.FromImage(lastBitmap))
                                {
                                    try
                                    {
                                        g.DrawImage((Bitmap)item.Value.Clone(), item.Key);
                                        g.Save();
                                    }
                                    catch
                                    {
                                    }
                                    finally
                                    {
                                        g.Dispose();
                                    }
                                }
                            }
                        }
                        this.pictureBox1.Image = lastBitmap;
                        this.Invoke(new Action(() =>
                                               { this.pictureBox1.Refresh(); }));
                    }

                    // Array.Clear(file, 0, file.Length);
                }
            }
            catch
            {
            }
        }