Robin 2 – Flash / NodeJS Multiuser Server Launch!

robinnode2

Robin has shed its winter feathers and is now based on a NodeJS backend.  Not only that but the Robin.as open source class for Flash AS3 has been preened.  Specific CLIENT_JOINED and CLIENT_LEFT events have been added along with supporting joined and left index properties.

droner

Droner – Mobile App to Control Friends – click to try

DotBot - complex avatar example with JSON - click to try

DotBot – complex avatar example with JSON – click to try

Robin 2 was coded specifically for the Dan Zen mobile app, Droner – http://droner.mobi where you get to control your friends – or let them control you!  The samples have all been recoded – not much of a difference on the Flash end – but we tightened up the code and added error checking.  A more complex example has been added called BOT – http://danzen.com/bot.  This shows a multiple part avatar being created and JSON being used to pass the data through the Robin multiuser server.

ROBIN 2 still provides amazing flexibility and clarity in Multiuser by the same simple concept of providing an Array of properties matching the properties of other users.

We have our Robin Server up and running on the Amazon Cloud EC2 – it costs us some money so if anyone is interested in chipping in – perhaps a deal can be made to host a project if you are in need of a node server.

The new download is available from the Download link – the old PHP version is no longer supported – sorry – but it is better this way!

Robin Future – Exploring Node.js for Multiuser with HCJ (HTML, CSS & JavaScript) as well as Flash

We ran our last Multiuser game – Nano2020 using Robin with PHP.  20 simultaneous people played it and it went well.  Later that night our server went down due to unattended threads.  Since then, using Robin has been a little like walking on egg shells.  We have some changes being planned for Spring 2013.

With the dawning of Node.js, we think that it would be a good idea to port the PHP sockets over to Node which is based on a powerful networking system made to handle sockets.  The Node language has the syntax of JavaScript so that should be no problem for Web and Flash developers to handle if they need to.  There is an issue of various hosts supporting Node.js.  It might be that we can work with free hosting – we are going to see.  Regardless, its popularity is bound to improve and it beats just being able to prototype.

FRONT END ADDITIONS

We have been very happy with the way Robin eliminates backend coding for multiuser.  We would like to introduce a few more front end methods to help with common tasks such as avatars, etc.  So we will try and provide that coding as Robin 2 pops its head up in the spring.

Looking forward to the future – hope you are too!

Dan Zen

Unique and Random Avatar Examples with Robin – Flash PHP Open Source Multiuser Server

We just finished a full-scale custom avatar game in Flash using Robin, the Flash / PHP open source multiuser server system.  Here are some screen shots – the launch date will be in June 2010.

You get to create a nanobot out of parts and scale and rotate them as well as set their layer or depth.  All this data is passed to Robin which then displays your nanobot on everyone’s screen and their bots get displayed on yours.  You then try and keep your bot in the lightest areas to pick up energy and you can also feed on their energy waste represented by pellets.  The goal is to stay alive longest.

The updated robin.zip file includes two Avatar examples.  The first allows you to assign unique avatars so everyone in the room gets the next avatar in a list.  The second example lets the user choose their avatar.  The code to customize your avatar like the nano example is not provided but follows the same structure and just adds basic Flash functionality.

Pay close attention to the various ins and outs of the ActionScript as the situation requires some careful code.

Robin Eggs – Diagram of Flash PHP Multiuser System

Example usage chart for Robin – the Flash / PHP multiuser system.

The white boxes are people using an application from their devices – each has their own color avatar.  When the Orange one moves, it sends its properties to Robin.  Robin then tells the others that there is new data.  The others ask for the properties.  All the properties (except for their own) get sent to them in an array (list).  So moving would require x, and y (maybe z).  They would ask for an array of x properties and an array of y properties.  You can also get the last value sent (and with another command find the index of the sender).

If you choose an avatar (say that relates to an image on one of ten frames), then you would send that frame number when you move – since you are sending several properties now, use setProperties() like so, assuming you have a Robin object running called myRobin:

myRobin.setProperties({x:10, y:20, avatar:7});

Others recieve a DataEvent.DATA event and they can get everyone’s x, y and avatar properties from getProperties(“x”), getProperties(“y”) and getProperties(“avatar”).  Each of these would return an array like this:

[22, 34, 10, 17] // array of x values
[44, 13, 20, 65] // array of y values
[1, 5, 7, 10] // array of avatar numbers
// if there are four others

Then you could loop through the array and position the avatar like so:

// make a private var players:Array = []; up top
// make an Avatar MovieClip in library export as class in properties
// Avatar clip has frames with different pictures
// when a person first comes in they would choose theirs 

if (myRobin.numPeople > 0) {
 var xProp:String; // x of an avatar
 var yProp:String; // y of an avatar
 var aProp:String; // frame number of an avatar
 // there could be blanks in getProperties from people leaving
 // so always cycle through the full length of getProperties
 // instead of cycling through numPeople
 for (var i:uint=0; i<myRobin.getProperties("x").length; i++) {
   xProp = myRobin.getProperties("x")[i];
   yProp = myRobin.getProperties("y")[i];
   aProp = myRobin.getProperties("avatar")[i];
   if (xProp != "") { // check for non blank
      if (!players[i]) { // check if we have not added avatar
        players[i] = new Avatar();
        addChild(players[i]);
      }
      players[i].x = Number(xProp);
      players[i].y = Number(yProp);
      players[i].gotoAndStop(Number(aProp));
    } else {
      if (players[i]) { // check to remove player  
        removeChild(players[i]);
        players[i] = null;
      }
    }
  }
}
setChildIndex(myAvatar, numChildren-1);

Sorry if it looks complicated… beats a hundred lines…

Oh… if you want to assign a unique avatar to each new person, just set var num:Number = getProperties(“num”) + 1; and then setProperties(“num”) = num; so that other new folks have the right number. Then use your unique num property to set the Avatar clip to frame number num.

You should run this code in the DataEvent.DATA but also in a Timer every 500 ms or so to catch anybody leaving by closing the browser.  This will get caught when people move but won’t get caught right away when people leave unless you do the timer.  You also want to run this code when people start so the other players come in right away.

Okay… looks like I should make some sample code for this 😉

Flash PHP Multiuser Server Running on XAMPP Windows

robin_l

Robin, the Flash PHP Multiuser set of classes, runs on XAMPP with a modification to the administration procedure.  As outlined in the readme.txt file, you do not run the admin page.  Instead, you just run the robin.php file directly.  Robin will run while the robin.php is running but because the posix family of commands is not available on XAMPP windows, this really makes it a testing environment.  If the PHP socket should go down, then there is no effective way to start it again.  Cron jobs would have problems in detecting if Robin is already running without the posix_kill command and thus run the risk of multiple sockets.

The Robin zip file readme.txt has been updated to better explain this.

Also added to the zip file is a clarification on how the provided samples work.  The samples will not work unless they are compiled (open the FLA files and CTRL ENTER to create SWF files) with your domain updated in the Robin.as file as instructed.

All the best,

Dan Zen

Robin for Flash Launches to Help Designers and Developers Create Flexible Multiuser Applications with Adobe Flash and PHP

robin_sample_blog

Robin lets you code flexible Flash real time applications like multiuser games, shared whiteboards and chats.  Robin is a custom AS3 class for Adobe Flash combined with a turnkey PHP socket system.  Please see the VIDEO and the sample CODE.

You only need to code in Flash ActionScript

Robin works on a simple principle.  You save properties such as your x and y position and you get to read other people’s properties such as their x and y positions.

FEATURES

  • Any number of application names
  • Unlimited users or specify how many people per “room”
  • History data for new people joining your application
  • Shared unique data available as an array
  • Optionally let new users fill in for users who have left
  • Get the latest updated property values at any time

If you are familiar with the Flash Media Server, the “latest property value” works like a shared remote object.

Robin’s strength is that, unlike a shared remote object in the Flash Media Server, you have control of everyone’s unique properties simply through an array.  So if you are saving a name property in a chat, you can access everyone else’s name property as:

["Dan Zen", "Colin Moock", "Nonoba", "AMFPHP" "RED5"]

When people update their text,  an event is triggered and this array is updated.

Robin has a host of other methods and properties but really, it just takes a couple lines of code to make use of its power.  Three samples are provided in the download:

  • a sample chat showing the history multi-room features
  • a multiuser game with avatars under unique control
  • a shared ball where anyone can move the ball

There is no back end PHP coding

You just set up PHP and set your Server address in the setUp.php file.  There is a simple admin system that lets you start your socket server.  All the tricky code has been written to provide real time data to the Robin Flash class. We suggest that you start Robin with a cron job although precautions are in place to restart the socket server should it stop.  Details are provided in the readme.txt in the Download ZIP.

robin_chart_blog

FRIENDS AND DONATIONS
Please let us know if you use Robin and we will add you to the Friends area at left.  If you use Robin for a commercial venture and would care to donate that would be super!

karmatja

FEATHERS
Robin is one of a selection of open source solutions called Flash Feathers available at http://flashfeathers.wordpress.com.

feathers

Dan Zen

-09-

%d bloggers like this: