Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys, I'm kinda in final stage of my final project. The last issue I'm facing is, my client is not showing video sent from server. While server is showing both, client's and own video. I'm sharing the code below which exists on both(Server, Client) sides. I've downloaded a project from codeproject.com in which same technique is used. Here's the code :

C#
bool isSending = false;
       private void CaptureDone(System.Drawing.Bitmap e)
       {
           try
           {
               this.ClientCam.Image = e;
               if (isSending)
                   ThreadPool.QueueUserWorkItem(new WaitCallback(SendVideo), ClientCam.Image);
           }
           catch (Exception) { }
       }

       private void Call_Button_Click(object sender, EventArgs e)
       {
           turnCamOffToolStripMenuItem.Enabled = false;
           turnCamOnToolStripMenuItem.Enabled = false;
           try
           {
               DirectX.Capture.Filters filter = new DirectX.Capture.Filters();
               capt = new DirectX.Capture.Capture(filter.VideoInputDevices[0], filter.AudioInputDevices[0]);
               if (capt != null)
               {
                   capt.PreviewWindow = ClientCam;
                   Call_Button.Enabled = false;
               }
               capt.FrameEvent2 +=new DirectX.Capture.Capture.HeFrame(CaptureDone);
               capt.GrapImg();
               isSending = true;
               thread1 = new Thread(new ThreadStart(ReceiveVideo));
               thread1.Start();
           }
           catch (Exception)
           {
               MessageBox.Show("Device is not accessible");
           }
       }

       public void SendVideo(object bufferIn)
       {
           try
           {
               TcpClient cll = new TcpClient(IP_Address.Text, 5000);
               NetworkStream strm = cll.GetStream();
               Image buff = (Image)ClientCam.Image;
               buff.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
               strm.Close();
               cll.Close();
           }
           catch (Exception)
           {
           }
       }

       public void ReceiveVideo()
       {
           try
           {
               skt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
               skt.Bind(new IPEndPoint(IPAddress.Any, 6000));
               skt.Listen(1);
               while (true)
               {
                   try
                   {
                       Socket server_sock = skt.Accept();
                       NetworkStream Nstream = new NetworkStream(server_sock);
                       ServerCam.Image = Image.FromStream(Nstream);
                       Nstream.Close();
                       server_sock.Close();
                   }
                   catch(Exception)
                   {
                   }
               }
           }
           catch (Exception)
           {

           }
       }


Please let me know where is mistake =[

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 23-Jun-12 23:24pm
v2
Comments
[no name] 24-Jun-12 19:35pm    
So you post this to have someone debug it for you? No thanks. I have much better things to do like watching the grass grow.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900