HTML and CSS Reference
At the very minimum, an extension contains what is known as a plug-in . A plug-in is a
stantiated and scoped to a room. For example, if you were making a card game, you
would want a card game plug-in on the server to handle things like shuffling the deck
and making sure the correct player wins a hand. In this way, the server holds the true
state of the game. Using an extension helps keep a game flowing and lessens the users'
ability to cheat. For the simple examples in this chapter, we will not be using any server-
side extensions. However, if you delve further into ElectroServer or other socket-server
applications, you should make sure to learn as much as possible about them.
Creating a Chat Application with ElectroServer
As an example, we are going to create a single chat application using the ElectroServer
displayed chat will be in HTML5 Canvas. We are also going to create and display some
messages from ElectroServer so you can see the status of the connection to the server.
Establishing a connection to ElectroServer
The client application makes a connection to ElectroServer running on a server at a
specific URL, listening on a specific port, using a specific protocol. For our examples,
this will be localhost , 8989 , and BinaryHTTP , respectively.
We need to use these values to make a connection from the client to the server. We do
this by first creating an instance of the ElectroServer object, and then calling its meth-
ods. We start by creating an instance of an ElectroServer server connection named
server . We then configure a new variable named availableConnection with the previ-
ous properties we described, then add it to the server variable with a call to the method
addAvailableConnection() . We will create all of this code inside our canvasApp()
var server = new ElectroServer.Server("server1");
var availableConnection = new ElectroServer.AvailableConnection
("localhost", 8989, ElectroServer.TransportType.BinaryHTTP);
Now, we need to use the server variable we just configured to establish a connection
to ElectroServer . We do this by setting a new variable, es , as an instance of the class
ElectroServer . We then call its initialize() method and add the server we just con-
figured to the es object by calling the addServer() method of the ElectroServer server
var es = new ElectroServer();