Android Tutorial Android based Closed Circuit TV (CCTV) example

Better example is available here: https://www.b4x.com/android/forum/threads/mjpeg-cctv-server.73792/

This example is made of two components:

Client - Basic4android program that takes the camera preview frames and sends them to the server.

Server - C# program that accepts incoming connections and shows the camera frames.

The code of both components is pretty simple and is a good example of creating network based solutions. Note that both the client and server components should overcome network problems and continue to work when the network is again available.

How to run this example
1. Find the desktop ip address (you can run ipconfig from the command line).
2. Set this address in the device program - ServerIp variable.

Most complicated step:
3. By default Windows firewall blocks incoming connection. You need to open the firewall settings and add an exception for port 17178 (TCP).
Windows 7:

SS-2012-11-22_17.12.41.png


Run the desktop program and press Start.
Run the device program and check the logs in the IDE.

The source code of both projects is attached as well as the compiled desktop executable.

This example requires Android 2.2+ as the API that converts the preview image to JPEG is not available on older devices. The reflection library is also required.

Feel free to ask any question about this implementation.

The client code was updated to use CameraEx class. Note that it requires Camera library v2.0+.
 

Attachments

  • CCTVServer.zip
    30.1 KB · Views: 4,401
  • CameraCCTVClient.zip
    10.3 KB · Views: 4,250
Last edited:

suciwulans

Active Member
Licensed User
Longtime User
program suddenly closed unexpected. i am using galaxy tab 2.0 screen blank. what should i do? this is bug?
 

suciwulans

Active Member
Licensed User
Longtime User
cctv example error

You can use this example with a local network or over the internet.

The second case is a bit more complicated. Assuming that you do not have a static ip address you will need to use a third party service that assigns a hostname to your dynamic address.

You will also need to add a "forward port" rule in the router.

There are many online tutorials that can help you with these tasks.

i try your code. unfortunately, program suddenly stop respond and get screen blank. this is bug? i use samsung galaxy tab 2.0:sign0085:
 

suciwulans

Active Member
Licensed User
Longtime User
error connecting

when i try connect from android to server, i got message " error connecting". windows firewall already turn off. what should i do?
 

suciwulans

Active Member
Licensed User
Longtime User
error conecting. Firewall already turn of. Wifi turn on, ip addres already set on pc. What wrong procedure?
 

Geezer

Active Member
Licensed User
Longtime User
Hi Erel,

I thought the example you gave was perfect for spying on the new puppy and expanded on it a little so I could have multiple cameras.

The attached files are the amended app and a new server file which allows up to 4 cameras.

Double clicking the camera view on the server opens a new popup you can watch.

Server is now in vb.net because I don't remember C# :BangHead:

The app itself now has a # button to cycle camera number 1 through 4.

Again, the code is mostly Erel's example, I just added to it. Hope it's useful.
 

Attachments

  • Multi CC TV Server.zip
    103.5 KB · Views: 1,064
  • Multi CC TV Client.zip
    10.8 KB · Views: 887

suciwulans

Active Member
Licensed User
Longtime User
This is a network problem. Can you ping the device IP address from the computer? Are you setting the correct IP in the device?

yes i can ping from computer. I still get error connecting on my galaxy tab 2.0. Any suggestion?
 

suciwulans

Active Member
Licensed User
Longtime User
Hi Erel,

I thought the example you gave was perfect for spying on the new puppy and expanded on it a little so I could have multiple cameras.

The attached files are the amended app and a new server file which allows up to 4 cameras.

Double clicking the camera view on the server opens a new popup you can watch.

Server is now in vb.net because I don't remember C# :BangHead:

The app itself now has a # button to cycle camera number 1 through 4.

Again, the code is mostly Erel's example, I just added to it. Hope it's useful.
Multi cc tv server and multi cctv client also ia got error connecting. scenario, i connect my pc to galaxy tab 2.0 ip all set, ping is ok but still cannot receive streaming camera from device to pc. any ideas? desperate.
 

suciwulans

Active Member
Licensed User
Longtime User
I got error for this example. i modified for IP and port address using edtip.text and edtport.text also btnstartstream button here is the code
after modified from cameraCCTVCLient.zip
B4X:
Sub Process_Globals
   Private frontCamera As Boolean = False
   Public ServerIp As String
   Public ServerPort As Int
   Private IntervalMs As Int = 150
   Private lastPreviewSaved As Long
End Sub

Sub Globals
   Private Panel1 As Panel
   Private camEx As CameraExClass
   Dim edtServerIP As EditText
   Dim edtServerPort As EditText
   Dim btnStartStream As Button
End Sub

Sub btnStartStream_Click
ServerIp=edtServerIP.Text 
ServerPort=edtServerPort.Text 
   StartService(Communicator)
End Sub

is it correct i modified the source code? thanks
 

cadcamman

Member
Licensed User
Longtime User
Closed Circuit TV (CCTV) example

Hi Guys

I get an error when i run this example, I have added a screenshot. i get the same error on my phone

can anyone point me in the right direction?

Thanks

Cadcamman
 

Attachments

  • errora.png
    errora.png
    76.9 KB · Views: 437
Top