Forum C# Serializable format for messages

Serializable format for messages

Postby koseki » April 19th, 2010, 3:29 pm

Hi everyone.
Just started using player.IO and got several problems with the usage of it.
We need to communicate with AS3 client with some sort of serializable messages, the most easiest way is to use native for flash AMF3 format. We found some realisations of AMF3 on C# and .NET, but Player.IO doesn't allow to use them, because it uses several libraries that are nor allowed in PLayer.IO.
Then we found Protocol Buffers format by Google. It is a very nice solution for us, but it couldn't be used with Player.OI for the same reason. It throws errors about classes that are not allowed in it.

So. I got a question. Is there way to make those things work within PLayer.IO?
Or are there any libraries that can be used for message objects parsing/serialisation between AS3 and C#?

What system do you use for sending and getting messages?
koseki
 
Posts: 4
Joined: April 17th, 2010, 8:32 pm

Re: Serializable format for messages

Postby Benjaminsen » April 20th, 2010, 10:17 am

The realtime multiplayer solution uses its own raw protocol that is heavily inspired by googles Protocol Buffers. To save bandwidth and latency we did however simplify the format further. This means that no type information, etc is parsed in the format itself.

All data is transfered using a very simple message object. '
C# documentation http://playerio.com/documentation/refer ... ry.message
AS3 documentation http://playerio.com/documentation/refer ... io.message

It is quite possible to build a RPC/Serialization protocol on top of this more raw protocol, but I would not recommend it for require low applications and games.

What are you aiming to build?
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Serializable format for messages

Postby koseki » April 20th, 2010, 10:43 am

We are aiming to make a turn-based fighting and we need to send lots of structured data. It is not very usefull to send data in raw types and parse it manualy. It will be much better to send whole objects as messages and to let the library parse/serialize it for us. Or a least we need to send arrays or maps of simple data in a structured format.

We could write our own high level protocol, but we have no time for it now and I think it is quite silly to write own library when we can use already writen services.
koseki
 
Posts: 4
Joined: April 17th, 2010, 8:32 pm

Re: Serializable format for messages

Postby Benjaminsen » April 20th, 2010, 11:00 am

Fair point,

As of now we do not support any RPC / Serialization format out of the box, but it might be worth looking into. Writing a small object wrapper around our message format should however be fairly strait forward using code generation (Similar protobuf)

I would love to look into it, but I am currently very tied up with working on the next major Player.IO release.

/Chris
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Serializable format for messages

Postby Vania » February 21st, 2011, 5:13 pm

I also need to send more structured data.
The game is turn-based too, I guess that's why the messages are come complex than in my previous real time game.

With just a way to send arrays I could do everything I need.
Vania
 
Posts: 198
Joined: March 24th, 2010, 9:01 pm

Re: Serializable format for messages

Postby Oliver » February 21st, 2011, 10:27 pm

With just a way to send arrays I could do everything I need.


messages are basically variable length arrays with typed values. You could easily build some sort of code generation that makes classes like so in C# and AS3 from your own format (psuedocode):

Code: Select all
class AttackMessage{
    public string Attacker;
    public WeaponEnum Weapon;
    public WayPoint Waypoint;
   
    public AttackMessage(Message read, int offset){
        Attacker = read.GetString(offset++);
        Weapon = (WeaponEnum)read.GetInt(offset++);
        WayPoint = new Waypoint(read, offset);
    }

    public Message Serialize(){
        var message = new Message();
        message.add(Attacker);
        message.add((int)Weapon);
        message.add(Waypoint.Serialize())
    }
}


Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Serializable format for messages

Postby tomoprime » February 24th, 2011, 6:07 pm

Unity Developers would be interested in having a method to serialize objects one way or another.

One being that to help synchronize gameObject state to all clients from the playerio server. Asking the developer to create his own Message wrapper to update a player's transform position, scale & rotation, with collider & rigidbody support in a bunch of x, y, z string messages is bit overkill. Unity allows drag and drop functionality of this by using State Synchronization or RPC, both covered in NetworkViews. Perhaps if people were to use a common drag and drop playerio game object sync script it would keep things tidy. :ugeek:

State Synchronization Details
You can enable State Synchronization per Network View by choosing what kind of data will synchronized in the Observed property.

Unity can pack/unpack some specific classes: Transform, Animation, Rigidbody and MonoBehaviour.
Transforms are serialized by storing position, rotation and scale. Parenting information is not transferred over the network.
Animation serializes each running animation state, that is time, weight, speed and enabled.
Rigidbody serializes position, rotation, velocity and angular velocity.
Scripts (MonoBehaviours) call the function OnSerializeNetworkView().
tomoprime
 
Posts: 12
Joined: February 6th, 2011, 12:55 am

Re: Serializable format for messages

Postby wildbunny » March 13th, 2011, 6:47 pm

Has there been any developments on a built-in serialiser/deserialiser yet?

Seems like the lack of one will mean serious amounts of time wasted for developers in the long run, as all but the simplest games will need this for multi-player...

Sure, you can serialise yourself but what happens when you add a new member to your class? You need to update both serialisation and deserialisation code, which will lead to bugs as it will inevitably be forgotten in some cases...

Fingers crossed something has been added :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Serializable format for messages

Postby Oliver » March 14th, 2011, 5:38 pm

Hey Paul,

Nothing has been added since last time on this subject. However, it's something that keeps popping up, so we're trying to figure out what a smooth solution would look like. We haven't find the perfect solution yet though.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Serializable format for messages

Postby wildbunny » March 14th, 2011, 6:24 pm

Oliver wrote:Hey Paul,

Nothing has been added since last time on this subject. However, it's something that keeps popping up, so we're trying to figure out what a smooth solution would look like. We haven't find the perfect solution yet though.

Best,
Oliver


Surely a wrapper around your message builder which uses reflection to parse the the types, builds and sends typed data, and then a decoder on the flash end would be ideal?

Basically like json but binary :)
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Serializable format for messages

Postby Benjaminsen » March 14th, 2011, 7:28 pm

wildbunny wrote:
Oliver wrote:Hey Paul,

Nothing has been added since last time on this subject. However, it's something that keeps popping up, so we're trying to figure out what a smooth solution would look like. We haven't find the perfect solution yet though.

Best,
Oliver


Surely a wrapper around your message builder which uses reflection to parse the the types, builds and sends typed data, and then a decoder on the flash end would be ideal?

Basically like json but binary :)


Honestly, the fact that we don't have anything like this already is that we really like to optimize the protocol for our games while still having a somewhat dynamic system. Something that is not really possible without either only supporting simple types or pre-defining message object formats.

Basically just sending complex objects adds a lot of wasteful overhead.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Serializable format for messages

Postby wildbunny » March 14th, 2011, 9:59 pm

Benjaminsen wrote:Honestly, the fact that we don't have anything like this already is that we really like to optimize the protocol for our games while still having a somewhat dynamic system. Something that is not really possible without either only supporting simple types or pre-defining message object formats.

Basically just sending complex objects adds a lot of wasteful overhead.


The thing is, reading this forum people are using json because there is no other way to do this through the api - json has to be a good order of magnitude slower and less compact than a binary serialisation would be.

So there is clearly a demand for a built in complex type serialisation - people who want raw performance would still be able to use the existing message building functions, but i'm guessing the development time saved would far outweigh the performance difference.

Having an in-house solution is especially important because the class white-list prevents the use of many third party serialisation libraries :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Serializable format for messages

Postby tomoprime » December 7th, 2011, 9:44 pm

overhead ? - Every developer shouldn't need to reinvent the wheel here. A pinned work around should be posted at least.

It kinda beats the point of having an authoritative server since every client can read & write every server message in clear text. Yikes!

Any updates here for the Unity crowd? We're moving into 2012...
tomoprime
 
Posts: 12
Joined: February 6th, 2011, 12:55 am

Re: Serializable format for messages

Postby jasonMcIntosh » December 8th, 2011, 7:04 am

I made my own wrapper for the PlayerIO Message class.

I mostly wanted type safety and to eliminate the possibility of referencing the wrong index for a given value, so each message wrapper subclass implements accessors for elements of its particular payload.

Code: Select all
public class StateChangedMessage : GameMessage // Implements IGameMessage
{
   public const string ID = "stateChanged";

   public StateChangedMessage( string newState ) : base( Message.Create( ID, newState ) )
   {
      // You can also create the Message instance here and use Add() to populate it.
   }

   public override string id
   {
      get { return ID; }
   }
      
   public string newState
   {
      get { return message.GetString( 0 ); } // This is the PlayerIO Message instance.
   }
}

It's not that much work. :)
Jason McIntosh
Otherwhere Gameworks
jasonMcIntosh
 
Posts: 81
Joined: February 25th, 2011, 4:51 am

Re: Serializable format for messages

Postby FuzzySlash » March 4th, 2015, 5:27 pm

Sorry for bumping an old topic, but it seems like JSON serialization still isn't available.

I'm thinking of rewriting my current MMO to work with Player.IO,
but only if there is at least ANY kind of serializer such as JSON that is compatible? It's really necessary for my game.

Thanks.
FuzzySlash
 
Posts: 37
Joined: April 15th, 2011, 3:59 am

Re: Serializable format for messages

Postby robertflesch » March 8th, 2015, 8:52 pm

Hi Fuzzy

I use tons of JSON objects in my project.
Just convert the JSON or Object data to a string.
then you can use something as simple as this.
Code: Select all
private function buildYOUR_MESSAGE_ID():void {
   var jsonToBeSent:String = getJSON();
   var dataTobePassed:Message = _connection.createMessage( YOUR_MESSAGE_ID );
   dataToBePassed.add( jsonToBeSent );
   _connection.sendMessage( dataTobePassed );
}

Just realized I gave an as3 example.
Check out this for C# example
https://gamesnet.yahoo.net/forum/viewtopic.php?f=18&t=2037&p=7485&hilit=decompress&sid=2807b149199beccfa2e3c437891049a2#p7485

If you passed this to another user, they would see in their handler for YOUR_MESSAGE_ID

static private function handleYOUR_MESSAGE_IDEvent( msg:Message ):void {
       var jsonString:String = msg.getString();
       // parse the String into JSON or object...
}

// This builds a json object out of local variables and embedded objects.
public function getJSON():String {
   var outString:String = "{\"yourData\":[";
   // call embedded object json
   outString = _yourEmbeddedObjectArray.getJSON(outString);
   outString += "],"
   outString += "\"myDataMember\":" + JSON.stringify(myDataMember);
   outString += "}"
   return outString;
}
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm


Return to C#



cron