Large-scale ActionScript multiplayer game networking (client and server)

Started by
5 comments, last by Sirisian 15 years, 6 months ago
I am considering the possibility of, within the next few years, completely remaking my browser-based MMORPG (which has been quite successful so far) into an entirely Flash/ActionScript-based MMORPG. After recently having begun to work with ActionScript, I have also begun to integrate ActionScript with PHP and MySQL by having the client make calls to web pages. It's easy enough and can produce awesome results in minigames, though obviously I have strong doubts that this would be the fastest method in a large, real-time game. Now my question is this: how best should a large-scale, real-time multiplayer game be set up in terms of networking for both the client and server? I have plenty of experience in C++ (though not quite in networking, so that will require much research, of course), and I imagine that the best solution may be to write the server in C++ and the client in Flash/ActionScript. If this is the case, I am looking for a heads-up on where to start researching the related ActionScript networking information so that I may research it extensively and first gain experience in multiplayer Flash programming before starting the potential remake. Also, although a bit off-topic, which database software (if any) would you recommend using in the C++ back-end?
Website (with downloads of my games)
Blog (updates on current projects)
Seeds of Time Online has returned!
Advertisement
You might want to look into SmartFox server.
First; thumbs up - c++ and as works very well together.

I also strongly recommend action script 3.0 to 2.0, because as 2.0 is not able to easily send binary data over the network, while as 3.0 has ByteStream objects where you can do ByteStream.WriteInt(2132); etc.

one of the first things you should do is write a class that is able to serialize the data the same way flash does (ie, so you can easily handle flashs UTF8 strings)

I wrote a backend for a irc-like chat system in c++, using QT library. (note: Commercial or open source licence required).
Its quite easy, but you have to remember to send back some xml data on the socket you want to connect to due to flash's security stuff.

Boost also has network library (asio)

If this is only going to run on unix, using raw sockets will give you no additional dependencies, and there are plenty of examples out there -- but it may cost you some additional time.
EDIT: Oh, and if you do this and send binary data, you have to remember to write endian converters!

It is also possible to write this in an interpeted language like Python or php, and it would scales well enough for lightweight games. Getting a prototype/mock of the server should go very fast. (the only bad thing here is that if you do make a typo, the compiler will not catch it for you, until the code decides to take the code path..)

For database i think you should go with something solid, like mysql, and just use one of the many apis/wrappers out there.
EDIT:
if you dont want to rely on an external db, SQLlite is quite good: http://www.sqlite.org/

Here is the first tutorial like program i looked at when starting to do as networking:
Server:
#!/usr/bin/php -q<?php/*Raymond FainUsed for PHP5 Sockets with Flash 8 Tutorial for Kirupa.comFor any questions or concerns, email me at ray@obi-graphics.comor simply visit the site, www.php.net, to see if you can find an answer.*/  error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); $address = '10.0.0.8';$port = 6155; //---- Function to Send out Messages to Everyone Connected ---------------------------------------- function send_Message($allclient, $socket, $buf) {foreach($allclient as $client) {socket_write($client, "$socket wrote: $buf");}}   //---- Start Socket creation for PHP 5 Socket Server ------------------------------------- if (($master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {echo "socket_create() failed, reason: " . socket_strerror($master) . "\n";} socket_set_option($master, SOL_SOCKET,SO_REUSEADDR, 1);  if (($ret = socket_bind($master, $address, $port)) < 0) {echo "socket_bind() failed, reason: " . socket_strerror($ret) . "\n";}  if (($ret = socket_listen($master, 5)) < 0) {echo "socket_listen() failed, reason: " . socket_strerror($ret) . "\n";}   $read_sockets = array($master); //---- Create Persistent Loop to continuously handle incoming socket messages ---------------------while (true) {$changed_sockets = $read_sockets; $num_changed_sockets = socket_select($changed_sockets, $write = NULL, $except = NULL, NULL); foreach($changed_sockets as $socket) { if ($socket == $master) { if (($client = socket_accept($master)) < 0) {echo "socket_accept() failed: reason: " . socket_strerror($msgsock) . "\n";continue;} else {array_push($read_sockets, $client);}} else { $bytes = socket_recv($socket, $buffer, 2048, 0); if ($bytes == 0) {$index = array_search($socket, $read_sockets);unset($read_sockets[$index]);socket_close($socket);}else{$allclients = $read_sockets;array_shift($allclients);send_Message($allclients, $socket, $buffer);}} }} ?>


Client

_root.serverloc = "svr.trayiel.com";
_root.serverport = "6155";
_root.socketConnect = 1;
_root.loseConnect = 1;
System.security.allowDomain('svr.trayiel.com');
msgArea.htmlText += "Please wait, connecting to server at "+_root.serverloc+" via port "+_root.serverport+".";
_root.chatSocket = new XMLSocket();
if (_root.socketConnect == 1) {
_root.chatSocket.onConnect = function(success) {
if (success) {
msgArea.htmlText += "Connection to server at "+_root.serverloc+" via port "+_root.serverport+" established!";
_root.socketConnect = 0;
} else {
msgArea.htmlText += "Connection to server at "+_root.serverloc+" via port "+_root.serverport+" failed!";
_root.socketConnect = 0;
}
};
}
if (_root.loseConnect == 1) {
_root.chatSocket.onClose = function() {
msgArea.htmlText += "Server connection lost!";
_root.loseConnect = 0;
};
}
XMLSocket.prototype.onData = function(msg) {
msgArea.htmlText += msg;
};
_root.chatSocket.connect("svr.trayiel.com",6155);
//--- Handle button click --------------------------------------
function msgGO() {
if (inputMsg.htmlText != "") {
_root.chatSocket.send(inputMsg.htmlText+"\n");
inputMsg.htmlText = "";
}
}
pushMsg.onRelease = function() {
msgGO();
};



mod edit: source tags instead of code tags.


[Edited by - hplus0603 on November 4, 2008 12:51:51 PM]
www.ageofconan.com
In general, networked games are large state machines who act to update a shared world database, and provide a view into (changes to) that world database to other connected clients.

How to structure a server for optimum performance is a rather large question -- there are lots of suggested links in the Forum FAQ for example. Also, for the very basics, try looking at this networked game loop description.

Finally, I second the recommendation to go with AS 3.0.
enum Bool { True, False, FileNotFound };
Thanks for the responses, guys.

Would the rest of you agree with _Kami_'s suggestion on looking into the Boost library's networking components for writing the server networking code?

Original post by hplus0603
In general, networked games are large state machines who act to update a shared world database, and provide a view into (changes to) that world database to other connected clients./quote]
Interesting; I was wondering about that very topic as well, and that clears it up.
Website (with downloads of my games)
Blog (updates on current projects)
Seeds of Time Online has returned!
I've no experience of Boost. To be honest, if I was writing a TCP-based game, I'd just go with raw sockets. Most of the APIs available just stick a thin veneer over the standard functions anyway.
I've been using Flash 10 for a few months now. I'd recommend developing with that. Make sure you read over the new Policy File information.

Another bit of advice. If you're going to be programming I recommend using FlashDevelop IDE with Flex. Much nicer environment for coders.

Oh yeah and if you need right click that problem was solved for most browsers except Opera

This topic is closed to new replies.

Advertisement