Android Tutorial Android based Closed Circuit TV (CCTV) example

Discussion in 'Tutorials & Examples' started by Erel, Nov 22, 2012.

Similar threads

B4A Tutorial MJPEG / CCTV Server
B4A Question CCTV between two mobiles
B4A Question Camera Preview Memory Leak?
Games [XUI2D] Example Pack
B4A Tutorial Intent Based Camera
  1. Erel

    Erel Administrator Staff Member Licensed User

    Better example is available here:

    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:


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

    Attached Files:

    Last edited: Dec 4, 2016
  2. NJDude

    NJDude Expert Licensed User

    It works great :)
  3. Erel

    Erel Administrator Staff Member Licensed User

    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.
  4. arenaluigi

    arenaluigi Well-Known Member Licensed User

    Very good Erel :sign0098:
  5. aaronk

    aaronk Well-Known Member Licensed User

    Hi Erel,

    I like it.. good one.

    But how would you send the image to a phone/tablet rather than a desktop PC program ?

    Also, can Audio also be done ?
  6. MLDev

    MLDev Active Member Licensed User

    It works great here! I'm going through the code now to see how it works. :D

    Thanks Erel
    Last edited: Nov 22, 2012
  7. androh

    androh Member Licensed User

    amazing :sign0098:
  8. Erel

    Erel Administrator Staff Member Licensed User

    It shouldn't be too difficult to create a server application that runs on the device. In that case you should initialize AsyncStreams in prefix mode and you do not need to send the size of the image.

    Audio can be done but it is more complicated as you need to implement some streaming protocol (unlike the video which is actually made of a series of frames).
  9. selvamurali

    selvamurali Active Member Licensed User

    Get Error while run CCTv example

    Hi Erel

    when i try to run your CCTV Client example i got the following error .

    let me know what i am missing. i attach the error screen shot .

    Attached Files:

  10. Erel

    Erel Administrator Staff Member Licensed User

    You should download the latest Camera library.
  11. JoanRPM

    JoanRPM Active Member Licensed User

    It works fine.
    Good job!
  12. NJDude

    NJDude Expert Licensed User

    I wonder if the "client" part could be modified to save the video locally, a new library maybe?.
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. NJDude

    NJDude Expert Licensed User

    I've tried that lib in the past and had some difficulties getting it to work on certain devices, this solution seems to work anywhere.
  15. icefairy333

    icefairy333 Active Member Licensed User

    great one!
  16. Erel

    Erel Administrator Staff Member Licensed User

    This is no simple way to convert the frames to a video.
  17. Azlan

    Azlan Member Licensed User

    Hi Just gave this a try.

    App on phone crashes.

    Log shows:

    Firewall, port settings etc ok. S3 phone with version 4.1.2

  18. NJDude

    NJDude Expert Licensed User

    True, I was just making a comment :D
  19. Erel

    Erel Administrator Staff Member Licensed User

    @Azlan you should update to the latest Reflection library.
  20. Azlan

    Azlan Member Licensed User

    Cheers Erel:)

    That fixed it.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice