Multiplayer Flash
Work has been slow the last few days, so I took the opportunity to learn how to do some simple networking stuff with Flash and ActionScript. The best way to do this seems to be through the use of the XMLSocket object. This is a partial misnomer, as it really doesn't need to send and receive XML at all, but it is a way to get a persistent socket.
You can't do direct peer to peer networking in Flash, but you can have a XMLSocket server to act as an intermediary. There are a number of existing ones (Swocket, Unity, etc.), some of which are free, but that's not much fun and the server can be pretty simple so I wrote my own. It's a barebones Java echo server which accepts connections from multiple clients. For the most part, whatever one client sends to the server is propagated to the other connected clients. The classic "learn to network" app is chat of course, so that's what I wrote. Once again I am really pleased with how easy Flash is to work with. Getting threads and networking up and running was not bad at all, and I was able to get a decent chat client done quite quickly. If you know how to format your messages, you can even join in the chat with a telnet session!
The nice part is that the server is so generic that you could use it for stuff more interesting than a chat application. It supports a few special commands that are extremely generic, like registering a nickname with the server, but beyond that it is just a dumb echo server. Deciding how to deal with a <chat> or <join> message is defined by the client. I am considering writing a Flash version of Santiago if things stay quiet. If anyone is interested in either the Java server or the ActionScript/Flash client, let me know and I can share it someplace.
1 Comments:
I like the Billy Madison inspired chatters in your screenshot. Who's Miss Lippy?
By Anonymous, at 6:05 PM
Post a Comment
<< Home