Flixel Forums

development => releases => Topic started by: Ohmnivore on Fri, Nov 22, 2013

Title: Streamy - Networking package for AIR
Post by: Ohmnivore on Fri, Nov 22, 2013
Well here's the product of two days of hard work, figuring out the obscure flash socket stuff and ditching python along the way.
Streamy. So what's Streamy? It's a package for online multiplayer networking. I'll be straight: it only works with AIR, although that already is cool because it can run on mobile platforms. It's a package that basically uses both UDP and TCP. One for the quick updates, like sending player positions, and the other for important stuff you can't afford to lose, like a chat message.

It was greatly inspired from this: https://bitbucket.org/reidyd/legume

I have a sort of hello world set up here: https://github.com/Ohmnivore/StreamyTest

It's pretty much done. At least it fills my needs. If there's any feature you want to suggest, go ahead.

Edit - I'm considering of making a TCP-only version of Streamy. So the poor players on their browsers will be able to connect too.
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Sun, Nov 24, 2013
Started a new project with Streamy, actually. http://ohmnivore.github.io/HeadRush/
Title: Re: Streamy - Networking package for AIR
Post by: Dovyski on Tue, Nov 26, 2013
That's really cool, congrats! I guess UDP is a better protocol for multiplayer games, but a TCP-only version for browser would be nice too. Maybe Streamy could configure itself based on the environment, so programmers can use a single API to work on pure AIR apps (games on mobile, for instance) or browser games.
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Wed, Nov 27, 2013
Yeah, actually TCP isn't that terrible once I tested it. I'm guessing gaffer on games' post made instilled an irrational fear of TCP in me. http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/
He really bashes it there.
This week at school is complete crap though so I'll only be able to work on it, like, next week.

PS: I might actually write reliable UDP. It seems like TCP interferes with UDP. There's like a paper about that out there somewhere.

Double PS: That auto-configure thing is cool! I actually just stumbled across site-locking and this
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html#playerType
Title: Re: Streamy - Networking package for AIR
Post by: Dovyski on Sat, Nov 30, 2013
TCP gets terrible when you have lots of packages and clients flooding the network. About the reliable UDP, I don't think that's a good idea.

If you want something reliable, then TCP is the way to go, since it is reliable by design. UDP, on the other hand, has no confirmation for packages, that's the reason why it's so fast compared to TCP. For a multiplayer game, for instance, when updating someone's position, it's ok to drop some package, since there are a lot of them coming and going.

If you drop a package in the current game loop iteration, that's not a problem, because the next iteration will fix the wrong position resulted from that dropped package.
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Sun, Dec 1, 2013
Yeah, well efficient non-blocking UDP would be a pain to write. Like what I mean is a form of UDP that would know when packets get lost, but won't block up the entire send chain till the packet is resent and confirmed. However packets will then arrive in an order possibly different than the one they were sent in. That was actually an issue when i wrote a project a while ago. Let's say the client is expecting to receive the map definitions, then to receive peers info, etc., it might be problematic if he receives peers info before map definition. Then i had to mess with storing peers info until the map was initialized.
So i'm thinking of making a reliable UDP that would actually block until a packet is confirmed, just so stuff comes in order, and i think it's gonna be soooo much easier to program.
Of course I'll keep the usual UDP, so all the regular updates can be sent through regular, while the important stuff can be sent through the poor man's reliable UDP.
Title: Re: Streamy - Networking package for AIR
Post by: Dovyski on Sun, Dec 8, 2013
Ok, now I see your point. Your are right, UDP has some problems, specially regarding the order the packages are received. Implementing the two approaches you described (a blocking UDP to ensure the order and the non-blocking/non-reliable one) seems a good plan to me.

About your project code, are you planning to move Streamy into its own repo on Github?
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Mon, Dec 9, 2013
Well I still find that Streamy is very incomplete.
TODO:
Flow control
Reliable in-order UDP

It's just that I'm working on a game that's going to use the library. So I'm sorta writing both in parallel, I'll be happy to share it all once it's done. Actually what I'm trying to do is build a game built on Flixel augmented with networking that will allow server-side and client-side mods as well as server plugins similar to the Source engine and its SourceMod modding. Overall I want it to feel like Quake ported to a 2D Source engine. So far the server handles multiple clients, moving, jumping, shooting. It just makes me happy to see things move. But there's still a looooot to do.
Cheers!
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Tue, Dec 10, 2013
OK, so I did some research for in-browser UDP. Well, it's entirely feasible. But, I'll have to switch to HTML5. Of course there's the almighty Photonstorm's Phaser engine I can use to port from Flixel.

Basically there's two ways UDP can be done in-browser: WebRTC (supported by loooots of browsers except IE I think)
-That's very nice, but then the server must be written in JS for WebRTC, right?

Google chrome API (chrome.socket)
-Requires the game to be a google chrome extension/app whatever the hell they call it. In my opinion that's not much of an issue, and at least this option gives raw access to UDP sockets. Makes me able to keep the server coded in AS3.
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Fri, Dec 13, 2013
OK, so I took a glance at Phaser and TypeScript. Both are awesome, but the TypeScript plugin for VS2012/VS2013 won't load. So uhm I'll try and use Cloud9 then. Anyways I just tried this piece of javascript as a google chrome app. Google chrome apps are somewhere in between an AIR app and a web swf. It works, tested with a python server.
P.S.: javascript code is a mess. oh my god. i miss as3 after 10min of fiddling with js.

Bottom line - I'm staying with AS3 as Google Chrome apps are like Adobe AIR apps, but tied to chrome instead of the air stuff. They're so desktopish that i don't see the benefit of switching to that from AIR.

Code: [Select]
chrome.app.runtime.onLaunched.addListener(function() {
    var clientSocket;
   
    // From https://developer.chrome.com/trunk/apps/app_hardware.html
    var str2ab=function(str) {
      var buf=new ArrayBuffer(str.length);
      var bufView=new Uint8Array(buf);
      for (var i=0; i<str.length; i++) {
        bufView[i]=str.charCodeAt(i);
      }
      return buf;
    }
   
    // From https://developer.chrome.com/trunk/apps/app_hardware.html
    var ab2str=function(buf) {
      return String.fromCharCode.apply(null, new Uint8Array(buf));
    };
   
    // From https://developer.chrome.com/trunk/apps/app_hardware.html
    // A client
    chrome.socket.create('udp', null, function(createInfo){
        clientSocket = createInfo.socketId;
   
        chrome.socket.connect(clientSocket, '127.0.0.1', 5805, function(result){
            console.log('chrome.socket.connect: result = ' + result.toString());
        });
   
        chrome.socket.write(clientSocket, str2ab('Hello server!'), function(writeInfo){
            console.log('writeInfo: ' + writeInfo.bytesWritten +
                'byte(s) written.');
        });
   
        chrome.socket.read(clientSocket, 1024, function(readInfo){
            console.log('Client: received response: ' + ab2str(readInfo.data), readInfo);
        });
    });
});
Title: Re: Streamy - Networking package for AIR
Post by: Dovyski on Sat, Dec 14, 2013
You have a nice goal for the project. I can't wait to see a multiplayer 2D Quake implemented using Flixel. Sounds so cool! :D

About UDP and the browser, it's a mess as you described. AIR is the most solid solution to keep your project simple. I like Chrome apps, they seem powerful and multi-platform, but I never had a chance to make a game using it.

Keep up the great work and let me know when you publish Streamy as a standalone project, so I can add it to As3GameGears (http://as3gamegears.com).
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Thu, Jan 16, 2014
Oh well, it's been around a month since I began working on HeadRush, an online multiplayer platformer shooter for AIR.
https://github.com/Ohmnivore/HeadRush
It has a newer version of Streamy with every feature I planned, but it's very badly written and it's two different libraries, one for the client, one for the server. I'll have to clean it up one day and merge both into one. But at least it works.

On another note, if you ever want a better solution for networking, I suggest using Haxe and wrapping around Enet/using the existing wrapper. Or you could roll your own networking library (why would you do this to yourself?) with the cross-platform hxudp wrapper.
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Fri, Apr 11, 2014
In the end I wrote this for Haxe: https://github.com/Ohmnivore/HaxeNet (https://github.com/Ohmnivore/HaxeNet)
Title: Re: Streamy - Networking package for AIR
Post by: Dovyski on Mon, Apr 14, 2014
Cool! That ENet lib you ported seems a good tool :)
Title: Re: Streamy - Networking package for AIR
Post by: Ohmnivore on Sat, Apr 26, 2014
Yeah, the port turned out pretty cool, and I'm using it for my game. I have a few other utilities utilities I'll share when I find the time.

A PHP master server for well uhm keeping track of servers -> I have one hosted at: http://skullrush.elementfx.com/laravel/public/
*my website seems to be down at the moment

Server discovery through LAN -> every game from Quake to Counter Strike to StarCraft has this feature

Mod file manager