I am creating a project for video surveillance. How do i send the live video to the client using socketing and Udp. I tried sending consecutive images to the client using tcp so that it finally looks like a video when viewed at the client side. But was not successful....
Please do let me know how to capture and send the video...

please paste that code within

This is the code i am working on...
It sends a single image to the client which is displayed in the client side without any problems.
But once the while-loop is introduced the program executes fine but there is no display happening in the client side.

I have used the WebcamCapture.dll

//------------------------------SERVER CODE-----------------------------

    public partial class Form1 : Form
    {
        int recv;
        byte[] data;
        IPEndPoint ipep;
        IPEndPoint sender;
        Socket newsock;
        EndPoint Remote;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            
            data = new byte[1024];
            ipep = new IPEndPoint(IPAddress.Any, 9050);

            newsock = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);
            newsock.Bind(ipep);
            sender = new IPEndPoint(IPAddress.Any, 0);
            Remote = (EndPoint)(sender);
            read();
           
            
        }
        public void read()
        {
            //recv = newsock.ReceiveFrom(data, ref Remote);
            //MessageBox.Show(Encoding.ASCII.GetString(data, 0, recv));
            
            //while (true)
            //{
                data = new byte[1024];
                recv = newsock.ReceiveFrom(data, ref Remote);
                MessageBox.Show(Encoding.ASCII.GetString(data, 0, recv));
            
                //textBox2.Text = Encoding.ASCII.GetString(data, 0, recv);
                
           // }

        }
               private void button2_Click(object sender, EventArgs e)
        {
            webCamCapture1.Start(5);
        }
//--------SENDING VIDEO-------------------
        private void webCamCapture1_ImageCaptured(object source, WebCam_Capture.WebcamEventArgs e)
        {

            Image image = e.WebCamImage;
            pictureBox1.Image = e.WebCamImage;
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            data = ms.ToArray();

            newsock.SendTo(data, data.Length, SocketFlags.None, Remote);
            
            webCamCapture1.Start(5);
           while(true)
           {
              listen(source, e);
           }
            
        }
        public void listen(object source, WebCam_Capture.WebcamEventArgs e)
        {

            
                Image image = e.WebCamImage;
               
                MemoryStream ms = new MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                data = ms.ToArray();

                newsock.SendTo(data, data.Length, SocketFlags.None, Remote);
                
            
            
        }
}




//----------------------CLIENT CODE--------------------

public partial class Form1 : Form
    {
        UdpClient udpc;
        IPEndPoint ep;
        Socket server;
        EndPoint Remote;
        IPEndPoint ipep;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender1, EventArgs e)
        {
             byte[] data = new byte[1024];
            string input, stringData;
             ipep= new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);

             server= new Socket(AddressFamily.InterNetwork,
                           SocketType.Dgram, ProtocolType.Udp);


            string welcome = "Hello, are you there?";
            data = Encoding.ASCII.GetBytes(welcome);
            server.SendTo(data, data.Length, SocketFlags.None, ipep);

            IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
            Remote = (EndPoint)sender;
            
                disp();
            

            

           
            server.Close();
        
        }
//-----------Displaying the image------
        public void disp()
        {
           byte[] data = new byte[102400];
           int recv = server.ReceiveFrom(data, ref Remote);
           MemoryStream ms = new MemoryStream(data);
           Image returnImage = Image.FromStream(ms);
         
            pictureBox1.Image = returnImage;
            data = Encoding.ASCII.GetBytes("OK");
            server.SendTo(data, data.Length, SocketFlags.None, ipep);
            disp();

        }
        
       
        
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.