Example #1
0
        protected override void Run()
        {
            byte[]        bytes = new byte[32768];
            byte[]        protocol;
            MemoryStream  ms = new MemoryStream();
            NetworkStream ns = client.GetStream();

            var newRgbValue = GetReadyBytes(out protocol);

            this.screenShotData = tmpShot;
            try
            {
                while (true)
                {
                    var length = BitConverter.GetBytes(protocol.Length);
                    ns.Write(length, 0, length.Length);
                    //ns.Read(bytes, 0, bytes.Length);
                    ns.Write(protocol, 0, protocol.Length);
                    //ns.Read(bytes, 0, bytes.Length);
                    ns.Write(newRgbValue.ToArray(), 0, newRgbValue.Count);
                    newRgbValue         = GetReadyBytes(out protocol);
                    this.screenShotData = tmpShot;
                    ns.Read(bytes, 0, bytes.Length);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Соединение разорвано:{0}", ex.Message);
            }
        }
Example #2
0
        void RunLowPics()
        {
            byte[]        bytes;
            MemoryStream  ms  = new MemoryStream();
            NetworkStream ns  = lowPicsClient.GetStream();
            var           msg = Encoding.Unicode.GetBytes("PREVIEW");

            while (true)
            {
                try
                {
                    ms.SetLength(0);
                    ns.Write(msg, 0, msg.Length);
                    int length = ns.ReadByte();
                    bytes = new byte[length];
                    ns.Read(bytes, 0, bytes.Length);
                    var firstPackage = Encoding.Unicode.GetString(bytes);
                    Console.WriteLine(firstPackage);
                    var    protocol          = firstPackage.Substring(0, firstPackage.IndexOf('|'));
                    var    protocolInfo      = protocol.Split('x');
                    string commad            = protocolInfo[0];
                    int    widthResolution   = Convert.ToInt32(protocolInfo[1]);
                    int    heightResolution  = Convert.ToInt32(protocolInfo[2]);
                    long   fullPackageLength = Convert.ToInt64(protocolInfo[3]);
                    var    fileInfo          = firstPackage.Substring(firstPackage.IndexOf('|') + 1);
                    var    cl_data           = new ClientScreenShotData(widthResolution, heightResolution,
                                                                        Utils.UnPacking(GetBytes(0, ns, ms, fullPackageLength, lowPicsClient)));
                    img.Dispatcher.Invoke(new Action(() =>
                    {
                        img.Source = ImageControler.ImageDeCompressor.CreateNewImage
                                     (
                            cl_data
                                     );
                    }));
                    Thread.Sleep(TimeSpan.FromSeconds(15));
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.")
                    {
                        break;
                    }
                    else
                    {
                        try
                        {
                            RdsControl.SetMainImageNewPic.Dispatcher.Invoke(new Action(() =>
                            {
                                RdsControl.MainWind.DeletePicture(ipAddress);
                                RdsControl.MainWind.CloseOutside();
                            }));
                            StopViewControl();
                        }
                        catch { }
                    }
                }
            }
        }
Example #3
0
        List <byte> GetReadyBytes(out byte[] btProtocol)
        {
            string answer;
            int    width  = Screen.PrimaryScreen.Bounds.Width;
            int    height = Screen.PrimaryScreen.Bounds.Height;

            System.Drawing.Size Coords = Utils.GetRectangleSize(width, height);
            int countHorizontalBlocks  = width / Coords.Width;
            int countVerticalBlocks    = height / Coords.Height;
            int totalBlockCount        = countHorizontalBlocks * countVerticalBlocks;
            var bytes = ImageControler.GetScreenshotBytes();

            this.tmpShot = new ClientScreenShotData(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, bytes.ToArray());

            List <byte> newRgbValue = new List <byte>();
            DateTime    start       = DateTime.Now;

            if (this.screenShotData != null)
            {
                List <int> blocks     = ImageControler.ImageCompressor.getChanges(width, height, Coords.Width, Coords.Height, countHorizontalBlocks, countVerticalBlocks, totalBlockCount, bytes, this.screenShotData);
                var        readyBytes = Utils.Compress(ImageControler.ImageCompressor.byteCompressor(blocks, bytes, Coords.Width, Coords.Height, countHorizontalBlocks, countVerticalBlocks, width, height));
                btProtocol = Utils.GetArraysProtocol(blocks, width, height, readyBytes.Length);
                newRgbValue.AddRange(readyBytes);
                Console.WriteLine("{0}ms Length:{1}", (DateTime.Now - start).Milliseconds, newRgbValue.Count);
            }
            else
            {
                var tmp = Utils.Packcage(bytes);
                answer = String.Format("{3}x{0}x{1}x{2}|", width, height, tmp.Count(), "ScreenShot");
                var bts = Encoding.Unicode.GetBytes(answer);
                btProtocol = bts;
                newRgbValue.AddRange(tmp);
            }

            return(newRgbValue);
        }
Example #4
0
        void RunImages()
        {
            NetworkStream ns = this.imageClient.GetStream();
            MemoryStream  ms = new MemoryStream();

            byte[]       answer;
            byte[]       lg        = new byte[8];
            BitmapSource source    = null;
            var          answerBts = Encoding.Unicode.GetBytes("OK");

            try
            {
                while (true)
                {
                    ms.SetLength(0);
                    int count = ns.Read(lg, 0, lg.Length);

                    //ns.Write(answerBts, 0, answerBts.Length);
                    var protocolLength = BitConverter.ToInt32(lg, 0);

                    //Regex reg = new Regex("^([0-9]+)", RegexOptions.Multiline);
                    //var match = reg.Match(str, 0);
                    //v Convert.ToInt32(match.Value);
                    //answer = new byte[protocolLength];
                    ms.SetLength(0);
                    answer = GetProtocol(ns, ms, protocolLength, imageClient, protocolLength);
                    //ns.Write(answerBts, 0, answerBts.Length);
                    long   allBytes          = 0;
                    var    firstPackage      = Encoding.Unicode.GetString(answer);
                    var    protocol          = firstPackage.Substring(0, firstPackage.IndexOf('|'));
                    var    protocolInfo      = protocol.Split('x');
                    string commad            = protocolInfo[0];
                    int    widthResolution   = Convert.ToInt32(protocolInfo[1]);
                    int    heightResolution  = Convert.ToInt32(protocolInfo[2]);
                    long   fullPackageLength = Convert.ToInt64(protocolInfo[3]);


                    if (protocolInfo.Count() == 4)
                    {
                        var fileInfo     = firstPackage.Substring(firstPackage.IndexOf('|') + 1);
                        var packegeBytes = Encoding.Unicode.GetBytes(fileInfo);
                        ms.Write(packegeBytes, 0, packegeBytes.Length);
                        allBytes = packegeBytes.Length;
                        var fileBytes = Utils.UnPacking(GetBytes(allBytes, ns, ms, fullPackageLength, imageClient));
                        data = new ClientScreenShotData(widthResolution, heightResolution, fileBytes);
                    }
                    else
                    {
                        List <int> blocks;
                        if (protocolInfo[4] != "[]")
                        {
                            blocks = Utils.GetRectNumbs(protocolInfo[4]);
                        }
                        else
                        {
                            blocks = null;
                        }
                        var fileInfo     = firstPackage.Substring(firstPackage.IndexOf('|') + 1);
                        var packegeBytes = Encoding.Unicode.GetBytes(fileInfo);
                        ms.Write(packegeBytes, 0, packegeBytes.Length);
                        allBytes = packegeBytes.Length;
                        byte[] fileBytes = null;
                        if (fullPackageLength > 0)
                        {
                            fileBytes = Utils.UnPacking(GetBytes(allBytes, ns, ms, fullPackageLength, imageClient));
                        }
                        ImageControler.ImageDeCompressor.ChangeCurrentPictureNew(data, fileBytes, blocks, widthResolution, heightResolution);
                    }
                    RdsControl.SetMainImageNewPic.Dispatcher.Invoke(
                        new Action(() => {
                        RdsControl.SetMainImageNewPic.Source = ImageControler.ImageDeCompressor.CreateNewImage(data);
                    }
                                   ));
                    ns.Write(answerBts, 0, answerBts.Length);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.")
                {
                    RdsControl.SetMainImageNewPic.Dispatcher.Invoke(new Action(() =>
                    {
                        RdsControl.MainWind.DeletePicture();
                        RdsControl.MainWind.CloseOutside();
                    }));
                    Console.WriteLine(ex.Message);
                    StopViewControl();
                }
                //MessageBox.Show(ex.Message);
                //if (responseThread != null)
                //    this.responseThread.Abort();
            }
        }