Android Tutorial MJPEG / CCTV Server

Not open for further replies.
A few days ago I've helped a developer with implementing a MJPEG client:
It was a good experience as while implementing it I've become familiar with the MJPEG protocol.
MJPEG is quite simple. Each frames look like:


<image data>

Note that the end of lines are made of Chr(13) & Chr(10) and not the standard Chr(10) which is the value of CRLF in B4A, B4i and B4J (this is the natural end of line character on those platforms).

This example turns the device into a CCTV camera. You can connect to it with any browser (including mobile browsers) and see the video stream. You can also access it over the internet if the router is configured to allow it.

The nice thing about this example is that it supports multiple clients.


Each connection is managed by a different instance of the "client" class. This makes it simple to support multiple and concurrent clients. AsyncStreams is responsible for the concurrency.

Note that the image sent as-is. The orientation might be wrong.

The frame rate is currently set to 6 frames per second. You can change it by modifying IntervalMS. Set it to 50 (1000 / 50 = 20 fps) and it will look much better.

Test it by running the app on the device and then enter the device ip address in the browser followed by the port (51042).

B4i example is available here:


    12.6 KB · Views: 3,063
Last edited:
Not open for further replies.