TechDoc: Different types of Socket connections

Posted on July 9, 2011

0


Basis

HotForestGreen uses a specific set of Socket connections with specific qualities for specific purposes.

Overview

  1. WebSockets – For HTML Clients. Read more about them in: “Web Sockets and Web Clients“.
    1. Requires a specifif IP Address – To connect to a HotForestGreen Server, the WebSocket needs to connect to a Known Server on a Known Web Address
    2. Are not binary – Even though WebSockets can support binary data, this is currently not supported by the HotForestGreen Server
    3. Streams per data package – Each data package or Message is streamed. Each Message is held Server Side until all data is in and parsed only then to all observers. this will create a minimal latency, based on package size and transfer speed.
    4. Uses an event based model – Each message sent is comparable with an Event.
  2. StandardSockets – As the name suggests, these are your run of the mill Sockets without any extra protocol
    1. Requires a specific IP Address – If you want to connect to a location online
    2. Allows for AutoConnect – Inside a local network: by scanning all local IP addresses for the existence of one or more HotForestGreen Socket Servers
    3. Are not binary – Even though standard Sockets can support binary data, this is currently not supported by the HotForestGreen Server
    4. Streams per data package – Each data package or Message is streamed. Each Message is held Server Side until all data is in and parsed only then to all observers. This will create a minimal latency, based on package size and transfer speed.
    5. Uses an event based model – Each message sent is comparable with an Event.
  3. StreamSockets – These Sockets are optimized to stream continuous data.
    1. Requires a specific IP Address – If you want to connect to a location online
    2. Allows for AutoConnect – Inside a local network: by scanning all local IP addresses for the existence of one or more HotForestGreen Socket Servers
    3. Is binary – To allow for binary streams
    4. Streams continuously – Each set of N bytes is immediately streamed to all observers, allowing for minimal latency
    5. Not implemented yet – Streaming Sockets are not implemented yet.

See also

  1. The HotForestGreen AutoConnect mechanism – In: “The Automated HotForestGreen Server Discovery mechanism“.
  2. Data Serialization and de-serialization – in “Using Comma Separated Value for efficient data transfer

Why is binary data not the standard?

HotForestGreen uses a very simple protocol, designed to work on most, if not all, platforms including Android, HTML, Flash, Java and C#.

The packages sent contain clear text data for the following reasons:

  1. Simplicity of design – Regardless of your platform, you can read and handle Socket Data that is clear text. Handling binary data can become very complex.
    1. Clear text format – Most data handled in systems are Strings and Numbers.
    2. ASCII Separators – To define the start and stop of the headers and the data sent within a package, ASCII separators are used to mark:
      1. <02> Start of text – Indicates where the Message Body starts
      2. <04> End of Transmission – To signal where the block of data ends.
      3. <30> Record separator – To state where a data row or record ends and a new one starts (see the next item: “Serialization and de-serialization of data”)
      4. <31> Unit Separator – To separate values and fields within a data row or record
    3. Serialization and de-serialization of data – Data is serialized and de-serialized using Lists (Arrays), ASCII based separators (see previous item) and operations on Lists (and Arrays) to Split and Join this data. This allows for very short and relatively fast code.

Everything is binary, no?

Everything we send via Sockets is binary data, with values from 0x00 to 0xFF. So far so good.

Reserved codes

But like WebSockets, some binary codes are reserved for specific use.

Sending truly binary data, like sound files or images, could lead to accidental occurrences of specific codes we use to separate data.

Fast serialization and de-serialization

In our case to separate data and allow for fast and simple Serialization and De-serialization.

Holding state

Currently, all packages sent to a Server are put in a “Holding state” until all data is in. Then they are distributed to all registered observers.

Socket for streaming data 

As binary data can be large (think files and images) or continuous (think audio and video streams) the best solution might be to have a Socket specifically for streaming data.

Advertisements
Posted in: Uncategorized