TechDoc: Simple HTTP server – Serving HTML and binary content in the cluster

Posted on May 10, 2011

0


Addressing the issue of serving Remote Controls, web pages and binary data

The SmartSpaces servers are very simple Socket Servers. Their goal is to provide a light weight infrastructure to distribute simple Text based messages through.

But how do you send images from one SmartSpaces Node to another? Or offer your Clients a Remote Control to some or all of your services, based on HTML or Flash?

What is lacking in the SmartSpaces Socket Servers – used to communicate between objects on different machines in the cluster – is the possibility to access and distribute web pages and binary content. So we need to do something extra to complete the SmartSpaces solution as a complete package.

To cover these issues, we use an embedded Simple HTTP Server.

The article below moves you through the design goals and different aspects.

Design goals

  1. Get an HTTP Server up and running without extra installs – The most important reason to include a HTTP server is to reduce the hassle when setting up a SmartSpaces Server Cluster with HTML and Flash based remote controls. Just running the SmartSpaces Server should cover all your needs to build whatever you need.
  2. Serving binary content – The main goal for the Simple HTTP server is to serve static binary content like Images, Flash-movies and HTML pages
  3. Allowing you to serve web pages – To offer interfaces to your SmartSpaces applications
  4. Supports the Socket Server – Serving binary content
  5. Not intended to run Server Side scripts – The Simple HTTP Server  will not run ASP, PhP or any other scripting. For that you can refer to the big boys.

SmartSpaces Socket Server? Messages in an application space

The messages distributed by the SmartSpacxes Socket Servers are – if you use the encapsuled framework:

  1. Serialized objects using JSON – Offered in Clear Text, with (char)02 and (char)04 as indicators for “start of text” and “end of text” indicators
  2. Events and commands containing serialized objects – Again using JSON

They run inside an application space. Meaning that to visualize whatever you receive via the Socket Server, needs to be pushed and translated to something else.

Which can – and should be – avoided.

Serving binary content without a Hassle?

So: what if you want to:

  1. Use Flash? – To offer cute interfaces and more sophisticated applications or remote controls
  2. Distribute images? – For instance: when you run a camera taking snapshots when something moves around in your house
  3. Give access to other content? – Like Audio and Video

For this the SmartSpaces Socket Server offers a simple HTTP server which:

  1. Listens to HTTP calls
  2. Serves (binary) content – From the local hard drive, based on the given link

Pulling data: distributing binary content without FTP

FTP is a push-technology. The Client decides where the Host will place the content, based on the liberties it is allowed via Server Side security settings.

Within the SmartSpaces Server Cluster, we want the Server to be in full control. The main reasons  are:

  1. Avoiding data pollution – (anyone pushing anything) on the Server
  2. Warrenting simplicity – FTP adds yet another protocol with yet more code and yet another need for authentication
  3. Avoiding an extra layer of security – We already have the Socket Server security layer. Adding FTP requires us to implement yet another layer.
  4. Easier to do: One to Many distribution – Is you want to distribute the content from one client to many servers, HTTP is what you need

Bottom line:

  1. Servers pull data from the Clients – using the Simple HTTP Server running on the “Client”.
  2. Clients send a “pull data” request to the Server – Using SmartSpaces Objects and SmartSpaces messages
  3. Servers are in control – They will pull in the content, based on who you are and what credentials it has on you. They will decide where to store that content.

No extra installs required

By default most computers come without a webserver installed.

The Simple HTTP Server embedded in the SmartSpaces Socket Server covers the basic scenarios you need to serve  more sophisticated content to parts in your cluster.

Leaving the heavy lifting to the big boys

If your application requires a more sophisticated server able to run PhP, ASP, JSP or any other server side coding work, use Apache, Microsoft IIS or any other similar technology.

Streaming binary data continuously?

It is possible your application will stream continuous data like: Audio, Video, or high resolution real time data from sensors. Stuff that is simply too complex or too much for the SmartSpaces Server.

There are several applications and solutions specializing in this kind of transfer. Flash and the Red5 Server can be used for streaming (and recording) Audio and Video from one source to many. Serving and streaming audio and video from static files can be done – again – using Flash.

The SmartSpaces Server can help you a long way. Depending on your network (transfer speeds between clients), the size of your data packages (based on how you encode data and how much meta-data is sent per package) and the efficiency of your and our code (to serialize and de-serialize the objects), you can get a long way, sending a lot of Clear Text based Data between hubs.

The run of the mill structure of the SmartSpaces Server is optimized in such a way that we keep overhead limited as much as possible, while still offering a “plug and play” kind of experience to keep coding on your side limited to the absolute necessary.

It is – however – intended for “normal use” and not designed (yet) for high performance / high demand type of solutions.

If you want to go more sophisticated directions on high-demand data streams, you will have to do some googling. The SmartSpaces Server does not cover this.

Research

Simple HTTP Server

  1. A simple HTTP Echo ServerJava2s – offering the basic code for a HTTP echo server returning a “Hello World”
  2. Create your own simple HTTP Serverdeveloper fusion – Including offering downloads of images / binary content
  3. C# WebserverCodePlex project – offering a simple HTTP multi-trheading  webserver
  4. Sample HTTP Server skeleton in c#Code Project – Code for DIY simple HTTP server

HTTP download

As discussed, the SmartSpaces Servers pull (binary) content from the client using the clients Simple HTTP Server. To do this, we need a downloader at the Server side. 

  1. Download files from webC# examples – Downloading a file from the web, directly to disk
  2. C# download file HTTPVisual C# kicks – A better documented article about the topic

Closing

With this approach we have the distribution and requests to HTTP / HTML / Binary Data covered.

  • Serving HTML pages – Clients can request HTML pages (with Remote Controls) from any Server in the Cluster
  • No dependencies to other installs – The HTTP based solution is up and running without dependencies to extra installs of a web server
  • Distribution of binary content covered – We can distribute binary (like images) content from one Client to many other machines
  • Servers, not clients, are in control – The Servers are in control of file “uploads” as they pull, instead of the client pushing (as is with FTP)
  • No protocol-overload – We keep our set of protocols limited
  • No extentions needed on security model – We can keep our security model simple
Advertisements
Posted in: techdoc