Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.2M
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 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 24 Jun 2012
Copyright © CodeProject, 1999-2014
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