What are Websockets?
Grabbed right off Mozilla's website, WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
My Demo
I've attempted to do two things with this websockets demo:
- Use a smartphone as a controller utilizing the accelerometer
- Create an MMO like engine that can have an unlimited number of controllers running at once
How it Works
The Server
At the core of a websocket application is a central server that receives messages and returns messages. I am using a simple python based server that is running on a computer at home. I also wrote the game engine in python which also runs on the server. When the server is pinged for data, it simply returns a parsable string that creates an array of x's and y's of each game object currently connected.
The Screen
The homepage of the project pulls all the data collected by the server and displays all the objects in real time. All objects are displayed relative to the size of your screen, so the relative position of all the objects are the same regardless of resolution or screen dimensions.
The Controller
Your phone connects to the controller page. This page does nothing more than take the accelerometer data from your phone and send it to the server roughly 6 times a second. Unlimited controllers can be connected at once and all objects will appear on the same screen, however I have not tested just how many controllers my set up can take before it starts having problems.
Live Demo
Open on your computer | Open on your phone