🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Making a multiplayer flash game

Started by
2 comments, last by Drizzt DoUrden 22 years, 9 months ago
I recently found out that Flash 5 can make multiplayer games. However when I tried to use it, I found it very confusing and generally I didn''t even know how to start. I am very familiar with flash but not its multiplayer abilites. Does anybody here know where I can find a tutorial to learn how to make multiplayer flash games? The help file lacks the information I need.
Advertisement
I saw your post a few days ago but didn''t have any information for you. But, as luck would have it, I just picked a new book (just published last month) that has exactly what you are looking for.

It''s called Flash Games Studio by Bhangal, Rhodes, et al ISBN 1-903450-67-5. It''s $49.99US/$74.95CAN.

I haven''t read any of it yet but from what I have glanced at the book looks like it has lot''s of cool game related stuff for Flash. Including a multi-player RC Racer game.

I hope this helps,

borngamer
There are two sides to the problem. The first side is the Flash and the other side is the Server.

In Flash, you use a XMLSocket to transmit the data. Basically, this sends the data over the network through telnet but there are a few restrictions. You can''t connect to a server that isn''t in the same subdomain as the Flash file. The XMLSocket doesn''t have to be used in conjunction with XML, it can be used to just send strings across the network in any way you want. This makes it really easy to send out your data with some sort of keying algo to mark what kind it is.

The Flashscript for a XMLSocket goes something like the following and it will be scattered around between your connect buttons and stuff. The actual socket.Connect would be run from a button press or something similar. I''ll assume you know enough about all that, because if you don''t even know how to make buttons work, you have no business trying to make multiplayer Flash stuff.


function myOnConnect(success)
{
if (success)
{
trace ("Connection succeeded!")
}
else
{
trace ("Connection failed!")
}
}


socket = new XMLSocket()
socket.onConnect = myOnConnect
if (!socket.connect(host,port))
{
trace ("Connection failed!")
}




If you specify null for the host argument, the host contacted will be the host where the movie calling XMLSocket.connect resides. For example, if the movie was downloaded from http://www.yoursite.com, specifying null for the host argument is the same as entering the IP address for www.yoursite.com.

To send data, you will use XMLSocket.send(object);. This converts the XML object or data specified in the object argument to a string and transmits it to the server, followed by a zero byte. If object is an XML object, the string is the XML textual representation of the XML object. The send operation is asynchronous; it returns immediately, but the data may be transmitted at a later time. The XMLSocket.send method does not return a value indicating whether the data was successfully transmitted.

To receive data, you will use myXMLSocket.onXML(object);. This is a callback function invoked by the Flash Player when the specified XML object containing an XML document arrives over an open XMLSocket connection. An XMLSocket connection may be used to transfer an unlimited number of XML documents between the client and the server. Each document is terminated with a zero byte. When the Flash Player receives the zero byte, it parses all of the XML received since the previous zero byte, or since the connection was established if this is the first message received. Each batch of parsed XML is treated as a single XML document and passed to the onXML method.

The default implementation of this method performs no actions. To override the default implementation, you must assign a function containing actions that you define. This means you will get to set up if you want the raw data parsed in whatever way you want using the callback function XMLSocket.onXML(object);. Just define the function in the main timeline and it parses your data automatically.

All of that is only half of the deal, you still have the server to cook up. Basically, the server will run like a simple telnet server. You have a few options here as to which language to use.
PHP: Slow and has a nasty time out. Also isn''t active.
CGI: Slow, but there is a nice socket interface in PERL.
Java, C, C++: All three of these are about the same, which the exception of Java being slightly slower and the other two more secure.

So basically, you just use a simple telnet-like data stream from within Flash and ship the data out to your custom made server. You can look around and find a few examples, but most of them suck. The best I have seen was a chat that included the java server.



Its ashame there are no tutorials on it, its not as hard as everyone makes it out to be... You could check out:

www.flashkit.com

www.virtual-fx.net

When I used to go there, there were no tutorials but its been a few years since anything I could not handle myself has come out. You should find many tutorials there, they may have some on XML Sockets.. take your time.



"I''ve sparred with creatures from the nine hells themselves... I barely plan on breaking a sweat here, today."~Drizzt Do''Urden
------------------------------Put THAT in your smoke and pipe it

This topic is closed to new replies.

Advertisement