Beispiel #1
0
        private void MessageCallBack(IAsyncResult Result)
        {
            Tuple <byte[], int, int> RData = (Tuple <byte[], int, int>)Result.AsyncState;

            byte[] SendData    = RData.Item1;
            byte[] SendBytesR  = new byte[SizeForOne + 4];
            int    SendCount   = RData.Item2;
            int    TotalLength = RData.Item3;

            //ChatBox.Items.Add(SendCount.ToString() + ":" + TotalLength.ToString());
            SendCount++;
            if (SendCount * (SizeForOne) > TotalLength)
            {
                return;
            }
            else if ((SendCount + 1) * (SizeForOne) >= TotalLength)
            {
                //ImageClient.BeginSendTo(SendData, SizeForOne * SendCount, TotalLength - (SizeForOne * SendCount), SocketFlags.None, IPBindPoint_ForImage, new AsyncCallback(MessageCallBack), Tuple.Create(SendData, SendCount, TotalLength));
                Client.Send(new byte[4]);
                ImageClient.SendTo(SendData, (SendData.Length / SizeForOne) * SizeForOne, SendData.Length - (SendData.Length / SizeForOne) * SizeForOne, SocketFlags.None, IPBindPoint_ForImage);
            }
            else
            {
                Array.Copy(BitConverter.GetBytes(SendCount), 0, SendBytesR, 0, 4);
                Array.Copy(SendData, SendCount * SizeForOne, SendBytesR, 4, SizeForOne);
                ImageClient.BeginSendTo(SendBytesR, 0, SizeForOne + 4, SocketFlags.None, IPBindPoint_ForImage, new AsyncCallback(MessageCallBack), Tuple.Create(SendData, SendCount, TotalLength));
            }
        }
Beispiel #2
0
        public void SendCaptureImageMethod()
        {
            MemoryStream ms = new MemoryStream();
            Bitmap       OrgImage;

            try
            {
                Bitmap C_Image   = CaptureImage(1920, 1080, 800, 700);
                Byte[] SendBytes = new Byte[(int)ms.Length];
                Byte[] SendBytesR;
                byte[] testbytes = new byte[15];
                int    width, height;
                width    = Screen.PrimaryScreen.Bounds.Width;
                height   = Screen.PrimaryScreen.Bounds.Height;
                OrgImage = C_Image;
                Client.Send(BitConverter.GetBytes(Screen.PrimaryScreen.Bounds.Width));
                Client.Send(BitConverter.GetBytes(Screen.PrimaryScreen.Bounds.Height));
                do
                {
                    ms      = new MemoryStream();
                    C_Image = CaptureImage(width, height, width, height);
                    C_Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    //CheckChange(C_Image,OrgImage);
                    var CompressedStream = new MemoryStream();
                    //var CompressStream = new DeflateStream(CompressedStream, CompressionMode.Compress,true);
                    var CompressStream = new GZipStream(CompressedStream, CompressionMode.Compress, true);
                    //ms = new MemoryStream();
                    ms.Position = 0;
                    Client.Send(BitConverter.GetBytes((int)ms.Length));
                    ms.CopyTo(CompressStream);
                    CompressStream.Close();
                    SendBytes = new byte[(int)CompressedStream.Length];
                    //SendBytes = new byte[3004];
                    CompressedStream.Position = 0;
                    CompressedStream.Read(SendBytes, 0, SendBytes.Length);
                    ChatBox.Items.Add(ms.Length + " : " + CompressedStream.Length);
                    CompressedStream.Position = 0;
                    Client.Send(BitConverter.
                                GetBytes(SendBytes.Length));
                    ms.Close();
                    CompressedStream.Close();
                    sw = false;
                    int count = 0;
                    do
                    {
                        SendBytesR = new Byte[SizeForOne + 4];
                        Client.Receive(new byte[4]);
                        Thread.Sleep(50);
                        for (int i = 0; i < SendBytes.Length / SizeForOne; i++)
                        {
                            Array.Copy(BitConverter.GetBytes(i), 0, SendBytesR, 0, 4);
                            Array.Copy(SendBytes, i * SizeForOne, SendBytesR, 4, SizeForOne);
                            //SendBytes.CopyTo(SendBytesR, 4);
                            //ImageClient.SendTo(SendBytes, i * SizeForOne, SizeForOne, SocketFlags.None, IPBindPoint_ForImage);
                            ImageClient.SendTo(SendBytesR, 0, SizeForOne + 4, SocketFlags.None, IPBindPoint_ForImage);
                            //ChatBox.Items.Add(ImageClient.ReceiveBufferSize);
                            Thread.Sleep(25);
                            //ImageClient.BeginSendTo(SendBytesR, 0, SizeForOne + 4, SocketFlags.None, IPBindPoint_ForImage,new AsyncCallback(MessageCallBack),Tuple.Create(SendBytes,count,(int)ms.Length));
                            //if((i+1)%5==0) Thread.Sleep(30);
                            //ChatBox.Items.Add(i + "번째");
                        }
                        Client.Send(new byte[4]);
                        //Thread.Sleep(10);
                        if (SendBytes.Length % SizeForOne != 0)
                        {
                            ImageClient.SendTo(SendBytes, (SendBytes.Length / SizeForOne) * SizeForOne, SendBytes.Length - (SendBytes.Length / SizeForOne) * SizeForOne, SocketFlags.None, IPBindPoint_ForImage);
                        }
                        Client.Receive(testbytes, 0, 4, SocketFlags.None);
                        count = BitConverter.ToInt32(testbytes, 0);
                    } while (count != -1);
                    GC.Collect(0);
                    GC.Collect(1);
                    ms.Close();
                    SendBytes  = null;
                    SendBytesR = null;
                    Client.Receive(testbytes, 0, 4, SocketFlags.None);
                } while (Client.Connected);
            }
            catch (OverflowException Ex)
            {
                ChatBox.Items.Add(Ex.ToString());
            }
        }