Click here to Skip to main content
11,496,146 members (683 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: C# Visual-Studio socket
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 :

 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 24-Jun-12 0:17am
Zainy95808
Edited 24-Jun-12 0:24am
(no name)1.3M
v2
Comments
Wes Aday at 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)

  Print Answers RSS
0 RyanDev 230
1 Sergey Alexandrovich Kryukov 114
2 Richard Deeming 100
3 OriginalGriff 89
4 Mostafa Asaduzzaman 59
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 24 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100