c # What is the best way to continuously send images through socket tcp?

0

I am using AForge more specifically in the video section of the ScreenCaptureStream class to get the bitmap of the computer screen and then send that image to a server which will show the images as if it were a video.

Perp the problem is that when showing the sequence of images in the server form is slow, taking about a second of difference to change the image, so my question is, what would be the best way to make a sort of streaming?

Server code:

TcpClient client = server.AcceptTcpClient();
                BinaryReader reader = new BinaryReader(client.GetStream());

                int size = reader.ReadInt32();

                //GZipStream stream = new GZipStream(new MemoryStream(reader.ReadBytes(size)), CompressionMode.Decompress);
                MemoryStream ms = new MemoryStream(reader.ReadBytes(size));
                //stream.CopyTo(ms);

                pictureBox1.Image = Image.FromStream(ms);

                client.Close();

Client code:

MemoryStream ms = new MemoryStream();
            //MemoryStream compress = new MemoryStream();

            //GZipStream gZipStream = new GZipStream(compress, CompressionMode.Compress);

            eventArgs.Frame.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            byte[] data = ms.GetBuffer();
            //gZipStream.Write(data, 0, data.Length);
            //data = compress.ToArray();

            TcpClient client = new TcpClient();
            client.Connect(new IPEndPoint(localAddr, port));

            BinaryWriter writer = new BinaryWriter(client.GetStream());

            writer.Write(data.Length);
            writer.Write(data);

            writer.Close();
            client.Close();
    
asked by Carlos Alexander 05.06.2018 в 09:38
source

0 answers