Publishers of technology books, eBooks, and videos for creative people

Home > Articles

ActionScript for Multiplayer Games and Virtual Worlds: Introducing ElectroServer

ElectroServer is one of the most-used socket servers for multiplayer Flash content. In this chapter, learn the concepts and terminology specific to ElectroServer, as well as how to install it and write a simple hello-world application. You'll also learn how to configure the server using the web-based administration system.
This chapter is from the book

IN CHAPTER 2, Connecting Users, we introduced socket servers—software that is usually running in a remote location, accessible over the Internet, that manages thousands of connections between client applications (in our case, games and virtual worlds). ElectroServer is one of the most-used socket servers for multiplayer Flash content.

In this chapter, you will be introduced to concepts and terminology specific to ElectroServer, as well as installing it and writing a simple hello-world application. We’ll also look at how to configure the server using the web-based administration system.

ElectroServer is free and unrestricted for up to 25 connected users (at the same time). You can download and install it at www.electro-server.com/downloads.aspx.

Server Concepts

In this section, we look at ElectroServer concepts and some terminology. Most of these concepts are popular and are shared by other servers as well. Since they are generally found in most socket server choices, the concepts described here are useful to learn about beyond ElectroServer itself.

Users

A user is a representation of a client connected to the server (and logged in). It is possible for a single client to establish more than one connection to the server and still be seen as a single user. Because of that, it should be noted that while a user usually has only one connection to the server, he can have more than one. For instance, to stream video from the server to a client using ElectroServer, a user establishes a second connection to handle the audio/video stream.

Rooms

A room is a common concept in the realm of socket servers that means a collection of users. In ElectroServer, a room is a way for one to many users to see each other and interact. If a user is in a room, then that user can send a chat message, which is then broadcast to all users in that room. That is a simple example of the use of a room. A user can be in multiple rooms at a time.

There are two types of rooms in ElectroServer:

  • Persistent—A room that always exists, even if there are no users in it. A persistent room allows users to join and leave at any time.

  • Dynamic—A room that is created for a single use. When the user list for that room drops to 0, meaning that all users have left, the room is destroyed. This is the most common type of room.

Rooms have many uses, the two most common of which are enabling chat and grouping users together to play a multiplayer game. Both of these common uses are explored in detail in later chapters.

Zones

A zone is collection of rooms. The concept of zones is mostly valuable as an organization tool for servers with large numbers of rooms. Rooms within a zone must be uniquely named. All users in a room within a zone have access to the room list for that zone. The user can subscribe to automatic list updates as the list of rooms changes.

If the room list is very large or very active (with many rooms being created and destroyed), you may find that connected users may receive too many updates per second to keep up with. Using more zones is one way to attempt to manage this.

Chat

Chat is the primary method by which users interact with each other while connected to a socket server. A chat message is text sent from one user to other users. In ElectroServer, as in many other socket server solutions, there are public and private chat messages. A public chat message is sent from a user in a room to that room at large—that is, broadcast to all users in that room. Typically, a public chat message would end up being displayed on the client in a text field, such as the one seen below.

A private chat message is sent from one user directly to one, or to many, specific other users. Unlike with public messages, the target user does not need to be in the same room as the sender, or in any room at all, for that matter. Most typically, a private chat message is from just one user to one other user, for example, to hold a private conversation between users in a chat room or to allow for private communication between players on the same team in a game. Many times in multiplayer games and virtual worlds, private messaging happens only between users who are considered buddies.

Buddies

Social networking is an enormous part of the typical multiplayer experience. In addition to playing games and competing, users like to form relationships that transcend a single play session. They like to flag each other as buddies to add to a list. When a user returns to the application on a future session, she sees her buddy list and can tell which of her buddies are currently online and which are not. A user can then message any of her buddies that are currently online and even challenge them to a game.

Some virtual worlds or social networks allow users to send messages to their buddies even when they aren’t online. When the offline user returns, he sees the delayed message that was sent.

EsObjects

This is the first concept introduced that is truly ElectroServer-specific. An EsObject is something that may look a little odd at first, but is tremendously useful as you become familiar with it.

An EsObject is a class that exists in identical form on both the server and the client. A new instance of the class is created and data is then stored on this object. The object can then be exchanged between the client and the server easily, because the transaction layer knows how to serialize and deserialize the object.

EsObjects are used all through the API for client-server communication. Here is an example EsObject created using ActionScript:

var esob:EsObject = new EsObject();
esob.setString("name", "Jobe");
esob.setInteger("age", 33);
esob.setStringArray("petNames", ["elfie", "bosley", "clyde"]);

You can see in the example above that first you create a new instance of the EsObject class, and then you add the data. Each property that you add to an EsObject has a strict data type. In the example above, you can see that String, Integer, and String Array are represented.

Here is the complete list of data types supported by EsObject:

  • String / String Array
  • Integer / Integer Array
  • Number / Number Array
  • Boolean / Boolean Array
  • Byte / Byte Array
  • Character / Character Array
  • Double / Double Array
  • EsObject / EsObject Array
  • Float / Float Array
  • Long / Long Array
  • Short / Short Array

You may wonder at first why putting all data on an EsObject is a good idea. It seems like it takes a good bit of code, and having to identify the data types seems like overkill. Well, it comes down to saving time (and headaches) later. By using EsObjects and strict data types, you reduce ambiguity in your code and are forced to program in a way that ends up being more manageable down the road.

Another benefit—both more and less visible—of using EsObjects is bandwidth. The serialization process used for EsObjects (which is hidden from you) generates packet sizes that are miniscule and hence keeps bandwidth to a minimum.

Extensions

In addition to providing a highly scalable connection layer, the most useful socket servers primarily provide a basic level of functionality right out of the box, like rooms, chatting, buddies, and a few other things. But what about features and functionality that you need for your game or world that are not part of the core feature set of the server you are using? A good socket server provides a way for you to add these features yourself. By extending the functionality of the server with your own custom code, you can achieve anything that you want to do.

ElectroServer and many other servers provide support for what are called extensions. An extension is custom code run on the server to provide features and functionality not built into the server.

An extension can include one or many types of objects to extend certain functionality of ElectroServer. There are three types of objects supported to extend and enhance ElectroServer: event handlers, plugins, and managed object factories. Each object can include variables to define values that should be known to the object upon creation.

Event Handlers

Event handlers allow a developer to have some custom logic applied as a result of an event. These are typically written in Java, although they can be written in ActionScript 1 as well.

ElectroServer currently allows event handlers to be created for the following event types:

  • Login—User is logging in to ElectroServer.
  • Logout—User is logging out of ElectroServer.
  • User Variable—User has updated the EsObject attached to the user object.
  • Room Variable—User has updated the EsObject attached to the room.
  • Buddy List—User has updated his buddy list (add / edit / delete).
  • Private/Public Messaging—User has sent a message to another entity (room / user).

Let’s take the Login event handler as an example. A client connects to ElectroServer and provides his login credentials. His name and password can then be authenticated against a database. The event handler then decides if it should accept or reject the user’s connection.

Plugins

Plugins (often written in Java) provide extended functionality where the core features do not offer what is needed. Clients can talk to plugins and plugins can talk to each other. ElectroServer supports two types of plugins: room and server.

Room plugins are in charge of any functions that may need to be attached to any particular room. Most often, these are used to handle game logic and additional room functions. A good example of a room plugin would be a card game: the plugin would handle all of the logic for dealing cards, which players receive them, score calculation, and deciding the winner. A room-level plugin is created and scoped to a room; thus, it is instanced. Clients can talk to any room-level plugin that is scoped to a room that they are currently in.

Server plugins extend the abilities that ElectroServer can perform. These may range anywhere from globally enhancing room functions to exposing an external interface to other applications that wish to leverage certain aspects of your game. Server-level plugins are created once and always exist, as opposed to room-level plugins, which are created as needed. Clients can talk to any server-level plugin.

A good example of a server-level plugin is accessing a remote RSS feed. If your virtual world required news entries to be displayed in-world in some way, then the server would need to load that news. In this case, it would be smart to have a server-level plugin that loads and manages the latest news, so that any other plugin can access it as needed.

Managed Object Factories

Managed object factories allow you to create instances of objects that need to remain active over time. One common object created through this kind of factory is a database connection. This will allow you to define the properties and database type to connect to and retrieve data from within a plugin.

Here’s an example of the creation of a MySQL-based managed object written for a Java-based plugin:

EsObject esDB = new EsObject();
esDB.setString("poolname","mysqlpool");
Connection c = (Connection)getApi().acquireManagedObject
→("ManagedDBConnection", esDB);

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020