Forum ‹ C# ‹ Serializable format for messages
14 posts
• Page 1 of 1
Serializable format for messages
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?
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
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?
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: 808
- Joined: January 12th, 2010, 11:54 am
- Location: Denmark
Re: Serializable format for messages
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.
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
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
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: 808
- Joined: January 12th, 2010, 11:54 am
- Location: Denmark
Re: Serializable format for messages
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.
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: 163
- Joined: March 24th, 2010, 9:01 pm
Re: Serializable format for messages
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
-

Oliver - .IO
- Posts: 1136
- Joined: January 12th, 2010, 8:29 am
Re: Serializable format for messages
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.
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().
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.
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
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.
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
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
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
-

Oliver - .IO
- Posts: 1136
- Joined: January 12th, 2010, 8:29 am
Re: Serializable format for messages
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
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.
Have more questions? Join us at #player.io on the freenode irc network. Making something cool with Player.IO? I would love to talk! My Skype handle is q-rious
-

Benjaminsen - .IO
- Posts: 808
- Joined: January 12th, 2010, 11:54 am
- Location: Denmark
Re: Serializable format for messages
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
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...
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
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.
It's not that much work.
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.
- jasonMcIntosh
- Posts: 83
- Joined: February 25th, 2011, 4:51 am
14 posts
• Page 1 of 1