Click here to Skip to main content
13,661,044 members
Click here to Skip to main content
Add your own
alternative version


209 bookmarked
Posted 25 Sep 2010
Licenced CPOL

C# \ VB.NET Camera Communication Libraries

, 15 Dec 2011
Rate this:
Please Sign up or sign in to vote.
Stream a live camera video stream or single images between applications using the TCP protocol.



I have seen a lot of people searching for a library capable of streaming a live camera video between two applications through the LAN or any other kind of network.

I myself needed it for my school project - but I couldn't find any free working library on the web, so I did some research and connected all of the different pieces to create this library.

This library allows you stream your camera video to another application written using the .NET Framework.

Although this article is written in VB.NET - you can use it with your C# projects too!

The camera stream should work well without any noticeable delays on your Local Area Network, but will lag when using it with an internet connection.

I used the ICam class developed by Pino to capture the camera frames; you can find the original ICam class here: (check out his site). In this project, I modified the ICam to fit my needs.


This library includes the camera capture class and the camera stream class. I separated this library to into two different ways of usage:

  1. As an ActiveX (a control) which allows you to drag and drop it to your form like any other control - including the host and the client method in the same control.
  2. As two classes; client and host, including some advanced methods for advanced users.

The main concept of this library is that the client that is connected to the image source (camera) sends the frames to the host (serializes the frame and then sends it); the host deserializes the image and updates the PictureBox/control.

Using the code - As an ActiveX

Use this if you want to stream your video in just a few short steps, no need for a lot of programming - drag and drop the control and write a little code.

Extract the "" attached, and you should find this directory: "TCPCamActivex\TCPCamActivex\bin\Release".

In your project, do the following:

  1. Open the Toolbox and right click on an empty space in the toolbox.
  2. Click "Choose items..." and a dialog should pop up.
  3. Enter the ".NET Framework Components" tab, and click on "Browse...".
  4. Go to the extracted directory path I mentioned earlier and import this file: TCPCamActivex.dll.
  5. Accept the dialogs.
  6. Now just drag the TCPClientActivex control to your form; this is where your camera frames are shown.

I called the ActiveX the same name on both the client and host applications - "Webcam". This ActiveX uses port 2020 by default.

On the host side application, we should start listening to any incoming connection, so we would use this method on the Form_Load event handler:

Webcam.StartListening() 'Opens the connection to accept clients

When you close the application, make sure to close the listening thread:

Webcam.StopListening() 'Closes the connection and does not accept clients

On the client side application, we should first connect the capture source (the camera). On the Form_Load event (or any other event you want) handler, do the following:

Webcam.Connect(IPAddress) 'Connects to the host (Replace the IPAddress variable)
Webcam.StartCamera() 'Starts up the camera to capture the video stream

Make sure to connect first and then start the camera! When you are finished and want to stop the connection and close the camera, do the following:

Webcam.Disconnect() 'Disconnects any open connection
Webcam.StopCamera() 'Stops the camera capture

ActiveX Events

This ActiveX comes with the following events:

  • OnFrameDraw(ByVal e As System.Windows.Forms.PaintEventArgs)
  • Connected()
  • Disconnected()
  • OnConnection()
  • LostConnection()

The OnFrameDraw event comes with the e as PaintEventArgs argument, which allows you to draw directly on the frame, and can be used on both sides.

The Connected and Disconnected events are only fired on the client side; every time a connection is successfully made, the control raises the Connected event. Every time a connection ends, the control raises the Disconnected event.

The OnConnection and LostConnection events are only fired on the host side; every time a client is connected, the OnConnection event is raised. Every time a client disconnects, the LostConnection event is raised.

You can handle these events to monitor your connection status and draw on the camera frames with GDI.

Using the code - As a class (Advanced)

Use this if you want to have some more control - like sending your own images, and choosing the PictureBox you want the frames to be drawn on.

Extract the "" file attached, and you should find this directory: "TCPCam\TCPCam\bin\Release".

On the host side, you should have a PictureBox control for the frames to be drawn on, and declare the TCPHost object (as a global variable):

Dim WithEvents Host As TCPCam.Host

On the Form_Load event handler, instantiate the class:

Host = New TCPCam.Host(PictureBox1, 8080)

PictureBox1 points to the PictureBox control you have on your form; 8080 is the port used in the connection.

Now add the following after the code above:

Host.StartConnection() 'Opens the connection to accept clients

On the client side, you should have a PictureBox control for the camera frames capture to be drawn on, and declare the TCPClient object (as a global variable):

Dim WithEvents Client As TCPCam.Client

On the Form_Load event handler, instantiate the class:

Client = New TCPCam.Client(PictureBox1) 'Set to null if you only you want to send images
Client.CameraFPS = 30 'The number of frames per second (refresh rate)
Client.CameraOutputSize = PictureBox1.Size 'Set the output size to the Picturebox size
Client.StartCamera() 'Start the camera video stream

Now we need to connect to the host, create a textbox or anything you want to get the IP address, create a button (the connection button), and in the Button_Click method, add the following:

Client.Connect(TextBox1.Text, 8080)

Replace Textbox1.Text with the IP address; 8080 is the port number the host uses.

You can use this class to transfer images instead of sending a video stream, just set the Picturebox1 variable to Null and don't use the CameraStart method. Every time you want to send an image, use the following method:

Client.SendImage(Image) 'Image is the image object to send

Class events 

The host comes with the following events:

  • OnConnection()
  • LostConnection()
  • errEncounter(ByVal ex As System.Exception)

The onConnection and LostConnection events are raised when a connection was created or a connection is lost, respectively. errEncounter is raised when an error occurs.

The client comes with the following events:

  • Connected()
  • Disconnected()
  • errEncounter(ByVal ex As System.Exception)

The Connected event is raised when a connection is successfully made, and the Disconnected event is raised when a disconnection occurs. errEncounter is raised when an error occurs.

BertMan Recordable TCPCam 

BertMan took the TCPCam library and added a recording capability at the client side. Download to use TCPCam with client recording capability. 

The modified code provides the StartRecording method to start a recording:

Client.CapturePathAndFileName = "c:\videos\myvideo.avi" 'The path of the recorded file
Client.StartRecording() 'Start the camera recording 

And use the StopRecording method to stop a recording:


Thank you so much BertMan for sharing this modified TCPCam code and helping others! 

Points of interest 

You can use the TCPCam library to transfer your camera video stream very easily from one application to another. Use the ActiveX to transfer the video stream easily, or use the classes to use some more advanced methods and send single images.

Using the ActiveX, you can draw on your video frames by handling the OnFrameDraw event and with some GDI coding.

Using this as a class, you can use OnPaint to draw on a new frame. This can be useful if you want to draw some graphics on your frame.

I have been searching for this kind of a library a lot, and I couldn't manage to find one - so I built my own. Hope it helps!


Using the TCPCam as an Activex to draw a weapon sight and remote control the nBot.


  • 15.12.11 - Added 
  • 26.09.10 - Added an example picture.
  • 27.09.10 - Changed the description to match the library.


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


About the Author

Software Developer Nemex Studios
Israel Israel
My name is Shay and I'm 21 years old.
At age 16 I created Nemex Studios (, an application development "company" (not official).
I'm the developer of "Mouse Recorder Pro", "Mouse Shaker" and many other applications, developed to help the community.

You may also be interested in...


Comments and Discussions

AnswerRe: can help me Pin
mricesnow28-Jul-11 1:53
membermricesnow28-Jul-11 1:53 
GeneralRe: can help me Pin
shynet28-Jul-11 5:35
membershynet28-Jul-11 5:35 
GeneralRe: can help me Pin
mricesnow28-Jul-11 15:56
membermricesnow28-Jul-11 15:56 
GeneralThanks Man.. Pin
hiteshs13-Jul-11 7:33
memberhiteshs13-Jul-11 7:33 
GeneralMy vote of 4 Pin
Amir Dashti11-Jul-11 16:35
memberAmir Dashti11-Jul-11 16:35 
QuestionI need help Pin
mw2adrian22-Jun-11 12:46
membermw2adrian22-Jun-11 12:46 
AnswerRe: I need help Pin
shynet23-Jun-11 5:37
membershynet23-Jun-11 5:37 
GeneralA problem about the Image Pin
datouhan29-May-11 22:37
memberdatouhan29-May-11 22:37 
GeneralRe: A problem about the Image Pin
shynet30-May-11 5:59
membershynet30-May-11 5:59 
GeneralRe: A problem about the Image Pin
datouhan1-Jun-11 15:55
memberdatouhan1-Jun-11 15:55 
Generalsaving images Pin
JeroenZonneveld30-Apr-11 3:23
memberJeroenZonneveld30-Apr-11 3:23 
GeneralRe: saving images Pin
shynet30-Apr-11 7:11
membershynet30-Apr-11 7:11 
GeneralRe: saving images Pin
JeroenZonneveld30-Apr-11 8:13
memberJeroenZonneveld30-Apr-11 8:13 
GeneralRe: saving images Pin
shynet30-Apr-11 8:55
membershynet30-Apr-11 8:55 
GeneralMultiply Webcam Pin
Member 776113518-Apr-11 19:13
memberMember 776113518-Apr-11 19:13 
GeneralRe: Multiply Webcam Pin
shynet18-Apr-11 21:37
membershynet18-Apr-11 21:37 
GeneralRe: Multiply Webcam Pin
homedb30-Oct-11 23:58
memberhomedb30-Oct-11 23:58 
GeneralRecord video Pin
Member 77611355-Apr-11 13:53
memberMember 77611355-Apr-11 13:53 
GeneralRe: Record video Pin
shynet5-Apr-11 19:48
membershynet5-Apr-11 19:48 
Questionreverse Pin
shivakantmanch4-Apr-11 21:36
membershivakantmanch4-Apr-11 21:36 
AnswerRe: reverse Pin
shynet5-Apr-11 0:58
membershynet5-Apr-11 0:58 
GeneralError Setting up camera Pin
Member 77611354-Apr-11 16:04
memberMember 77611354-Apr-11 16:04 
GeneralRe: Error Setting up camera Pin
shynet5-Apr-11 1:03
membershynet5-Apr-11 1:03 
GeneralRe: Error Setting up camera Pin
Member 77611355-Apr-11 4:40
memberMember 77611355-Apr-11 4:40 
GeneralRe: Error Setting up camera Pin
shynet5-Apr-11 5:29
membershynet5-Apr-11 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05-2016 | 2.8.180810.1 | Last Updated 15 Dec 2011
Article Copyright 2010 by shynet
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid