Fork us on GitHub

On Device Web Server

This cn1lib slipped through the cracks when we added it
On Device Web Server

On Device Web Server

I try to write about every new feature or capability we introduce but this isn’t always possible. Tasks sometimes weigh me down and as they do so I sometimes find something that I totally neglected as it was released. Such is the case with the CN1Webserver library which we launched over 6 months ago.

It got lost and in fact it came out during such a busy period I completely forgot about it.

This cn1lib lets you create a simple web server on the device. You can then connect to this server either from the device itself (the more common use case) or remotely.

This sounds insane but it’s a surprisingly common trick used by developers to get around odd device limitations. I first ran into this use case around 2010. Back then a company I was consulting for needed a way to process media files before playback (to apply DRM). This was impossible in Android at the time and it’s still challenging. Their solution was genius and trivial: they implemented a webserver on the device.

This way they could download and decode the file locally, then playback from a local URL on the device itself. The devices media API was oblivious to the fact that DRM was used in playback.

There are quite a few additional cases such as the ability to embed HTML/JS code that needs server interaction in order to work. For most of us this feature is pretty niche but the fact that you can accomplish it with a simple plugin is huge.

You can install the cn1lib like you can any other cn1lib from the Extension Manager. You will need additional setup so it will work correctly on the devices as explained in the github project.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.