Author Topic: Easy Networking  (Read 6162 times)

increpare

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Easy Networking
« on: Sat, Dec 5, 2009 »
I was thinking it might be nice to have some sort of generic and networking module for flixel that would allow people to do stuff without doing complicated/finicky/expensive server-hosting stuff.

The ideal setup for me on the user-end would be
I go to play a game.  I press the 'new game' button.  At any time, if i want a friend to join me, I send them a copy of my current url, and they just go there to play with me.  Or some sort of very simple action for people to do.

While it might not be the best approach, I think some sort of generic java server, maybe made to be compatible with google apps (because it's free within small usage limits).  Client-side, you could have an array of 'playerdata' objects that are sent to the server, and the server can more or less blindly replicate them (let's assume that cheating and security aren't at all prioritized).  You might want to specify an update rate, and possibly replication rules.

Or maybe something as basic as message-passing might suffice for a start (let every state have an onRecieve(from,message) function).  Some really ultra-lightweight interface.  How lightweight can one reasonably get?

Anyway, the ideal situation would be to be able to have a generic server app that you could just thwap up anywhere (self-hosted, or somewhere free, or somewhere expensive), and then you write your game entirely in as3 and hopefully without too much confusion.  

I rarely let myself get caught up by these sort of feelings, but in this case it feels like something that would be worthwhile: I'd like to write some net games, but it's always such a pain to deal with C/S stuff and then to expect people to coordinate to play (especially if you expect them to host their own servers).

I guess flixel is chiefly designed for actiony platformy games, and these are the sorts of games that require nuanced realtime networking.  It's no doubt impossible to hide entirely the nitty-gritty of networking for people who want to have games with lots of stuff going on, but one would think something really nice and lightweight should be possible.

I think I feel this is important enough for me to be worth putting effort into, but I'd like to here other people's opinions first.
« Last Edit: Sat, Dec 5, 2009 by increpare »

ChevyRay

  • Member
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
    • The Proper Undead
Re: Easy Networking
« Reply #1 on: Sun, Dec 6, 2009 »
Excellent idea, and very worth pursuing if you ask me. I would use the bajeebs out of something like this. I also am very partial to the idea of being able to copy/paste a URL to have friends/others join a session, that sounds user-friendly to the extreme. Reminds me of Captain Forever's excellent ship-loading functions.

I wish I knew more Java so I could help put such a thing together.

Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
Re: Easy Networking
« Reply #2 on: Sun, Dec 6, 2009 »
Jeff Lindsay aka Progrium aka the Tigsource IT guy has actually started building a some stuff to do this.  He's still checking out servers afaik, I think he's considering Three Rings' java server most recently?  I have a silly co-op zombie slaying prototype that we're gonna use as a testbed, but if you get in touch with him i'm sure he'd add you to his github project so you could see the files he's got so far.  He made a combat tanks demo thing during tigjam that was pretty successful, if a little jumpy...

also I agree that it is super awesome and important and I'm hoping it will be an official part of flixel sometime around GDC!!

increpare

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: Easy Networking
« Reply #3 on: Mon, Dec 7, 2009 »
Cool.  I'll see if I can do prototype something this weekend for LD.  If I manage to survive that experience with my enthusiasm intact, I'll get in touch with Progrium : )

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
Re: Easy Networking
« Reply #4 on: Mon, Dec 7, 2009 »
AFAIK Flex can only comunicate throught XML, but it could be possible to optimize that with some base64 or hex packing in a single tag.

I think the SFML has a quite fast and understandable interface.
You can derive from Packet to have custom packets or just use "sendString/sendInt8,16,32,64/sendFloat" or something like that. You should check it out.

Making a dumb proxy app will only help in 2 player coop mode. If more players are needed to interact, then a client-server configuration is mandatory. But making it in action script would kill performance pretty bad (having to go through the proxy and back to everybody... waiting the server AS3 to process and respond)

If you need another hand on this, I can help.

Regards

increpare

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: Easy Networking
« Reply #5 on: Mon, Dec 7, 2009 »
Making a dumb proxy app will only help in 2 player coop mode. If more players are needed to interact, then a client-server configuration is mandatory.
Why?  I can imagine that there are some sort of events you'll want the server to echo before you react to (important state changes that you want to be received in the same order on ever client).  But in general it should be manageable?  With the possible exception of NPCs.  I think the main problem, in fact, is with NPCs (things that traditionally the server would have control over) rather than players-controlled entities.

Quote
But making it in action script would kill performance pretty bad (having to go through the proxy and back to everybody... waiting the server AS3 to process and respond)
I was thinking of doing the server in java in any event.

Quote
AFAIK Flex can only comunicate throught XML, but it could be possible to optimize that with some base64 or hex packing in a single tag.
AS3 has a binary socket class (cf here).
« Last Edit: Mon, Dec 7, 2009 by increpare »

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
Re: Easy Networking
« Reply #6 on: Mon, Dec 7, 2009 »
Cool  ;D Thanks for the info.

Answering the first question:
Let's say client 1 shoots a constant-velocity bullet.
c2,c3 and c4 receives that command at different moments.

c1 must keep sending "updates" to the position of the bullet all the time (to synchronize), keeping track of each bullet it generates itself.
It takes two hops each update, 1 to the dummy proxy server, 1 to the other client.

Now let's say we have 1 bullet per second. It's a mess.

Having an intelligent server that keeps track of the positions and does the simulation itself, then clients:
1. don't have to keep track of anything: They just trigger events and handle updates.
2. only have 2 hops the first time (trigger and update), and then 1 hop per update from the server
3. If a client disconnects, the state of everything he's handling doesn't die with him.

Sync'ing is way easier.

Regards

lithander

  • Active Member
  • ***
  • Posts: 222
  • Karma: +0/-0
    • View Profile
    • pixelpracht
Re: Easy Networking
« Reply #7 on: Tue, Dec 8, 2009 »
If you try to write your own client/server solution I suggest you have a look at JSON (http://json.org/) for the serialization/deserialization of Objects.

var objectToSend:Object = ???
var json=new JSONEncoder(objectToSend);
var jsonData=json.getString();

You receive a string and just send that over a socket (flash.net.Socket). If you receive data you can create the original object from the string.

var json=new JSONDecoder(jsonData);
var receivedObject:Object = json.getValue();


As easy as it can get! :)

On the server side Pushbutton Engine offers an interesting solution where the server is written in AS3 and interpreted in the same virtual machine that Flash uses (Tamarian) just running on the server instead of within the flash player. So basicall the server can use the same classes as the client and you don't have to get involved in a new language to implement server-side logic.
Simplicity is the ultimate sophistication ~Leonardo Da'Vinci

nitram_cero (2bam)

  • Contributor
  • ****
  • Posts: 484
  • Karma: +0/-0
    • View Profile
    • 2BAM
Re: Easy Networking
« Reply #8 on: Wed, Dec 9, 2009 »
On the server side Pushbutton Engine offers an interesting solution where the server is written in AS3 and interpreted in the same virtual machine that Flash uses (Tamarian) just running on the server instead of within the flash player. So basicall the server can use the same classes as the client and you don't have to get involved in a new language to implement server-side logic.

That is quite cool indeed :)

axcho

  • Active Member
  • ***
  • Posts: 174
  • Karma: +0/-0
    • View Profile
    • Evolution Live!
Re: Easy Networking
« Reply #9 on: Thu, Dec 10, 2009 »
It would be so awesome if something like this were available for Flixel. I would definitely use it. 8)

PushButton does have an interesting approach. Given how Flixel and PushButton compare, it would be funny if Flixel did get its own networking component.

While PushButton's approach seems to favor flexibility and power, Flixel seems to focus on simplicity and speed, and it would be nice to see that philosophy expressed in its networking implementation as well.

Socapex

  • Active Member
  • ***
  • Posts: 156
  • Karma: +0/-0
    • View Profile
Re: Easy Networking
« Reply #10 on: Fri, Dec 11, 2009 »
Actually, Adam has mentioned he'd like to add basic multiplayer support: "some kind of magical light network thingy for online multiplayer" said Mr. Atomic. Yay, more thingies ;D
Free cake every day at #flixel on irc.freenode.net.
Use your favorite IRC client or  http://webchat.freenode.net/

increpare

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Re: Easy Networking
« Reply #11 on: Sat, Dec 12, 2009 »
Stratus seems like a very promising possibility for (almost) pure peer-to-peer communications.  Pity it's still in beta.

GaryBiscuit

  • Guest
Re: Easy Networking
« Reply #12 on: Thu, Dec 31, 2009 »
Isn't SmartFox supposed to be pretty top-shelf? I've never used it, but - as far as I can tell just from looking at the SmartFox site - it seems to be one of the most robust solutions for multiplayer Flash games. I was surprised no one mentioned it on this thread... Am I missing some real negative aspect of it (other than the cost)?

- Gary

vonWolfehaus

  • Active Member
  • ***
  • Posts: 247
  • Karma: +0/-0
    • View Profile
    • Cold Constructs
Re: Easy Networking
« Reply #13 on: Thu, Dec 31, 2009 »
Isn't SmartFox supposed to be pretty top-shelf? I've never used it, but - as far as I can tell just from looking at the SmartFox site - it seems to be one of the most robust solutions for multiplayer Flash games. I was surprised no one mentioned it on this thread... Am I missing some real negative aspect of it (other than the cost)?

- Gary
SmartFox is not "light" and the cost is significant (any cost is too much). To jive with the Flixel Way I'm guessing an FlxMultiplayer thingy needs to be free and cheap (as in CPU) so we're not looking for robustness, just clean efficiency and enough features to Do The Deed.

I posted elsewhere that Stratus is probably our best bet for such a thing. It's light and fast and free. You just need to grab a dev API key (free and easy to get) to use Adobe's Stratus servers as an anchor (the actual transfer of bytes is peer-to-peer).
Meet Obama every day at #flixel on irc.freenode.net.
Use your favorite IRC client or  http://webchat.freenode.net/

GaryBiscuit

  • Guest
Re: Easy Networking
« Reply #14 on: Thu, Dec 31, 2009 »
(Knowing nothing about how Flash multiplayer games work): Is Stratus structured in such a way that would support real-time multiplayer games (as opposed to turn-based)?

- Gary

echeese

  • Guest
Re: Easy Networking
« Reply #15 on: Thu, Dec 31, 2009 »
Yeah, i've been able to get <100ms pingtimes cross-country.
Edit: In fact, I'm working on something for this, myself. I've currently got Mode working with multiplayer. Hopefully I'll have a demo when I get it polished. Also, what can you guys tell me about text input?
« Last Edit: Thu, Dec 31, 2009 by echeese »