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:

Giuliano Cucchiarini

Member
Licensed User
Longtime User
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+.

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+.

Is it possible to add also AUDIO?
 

Beja

Expert
Licensed User
Longtime User
Server - C# program that accepts incoming connections and shows the camera frames.
Hi Erel,
I understand b4j was not released at that time.. but I am not familiar with C# and have little time to study it (if interested at all)
Is there any plans to port the server to B4J?

Thanks in advance
 

jonydoboi

Member
Licensed User
Longtime User
I get this error message.
Do have B4A 2.30
I deleted the designerscript and the program compiled but still had an error.
An error has occurred in sub: cameraexclass_takepicture (java line: 451)
NullPointerException.
It is a front facing camera.
 

Attachments

  • Error.jpg
    Error.jpg
    82.3 KB · Views: 441
Last edited:

sasidhar

Active Member
Licensed User
Longtime User
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+.


Does this Example works if the IP is Static IP and Server Application at this Static IP.
 

sasidhar

Active Member
Licensed User
Longtime User

I tried with Local WIFI 192.168.1.4 is the IP and port as mentioned 17178.

Port Added in windows Firewall settings

When I Run Application from Mobile I get Error Connecting..

Log"(ErrnoException) libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)"

I have disconnected B4A Bridge also, still same issue.

Please let me know what could be the issue..

Thanks
Sasidhar
 
Top