How to create a generic Java .net (C#) protocol?

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

Posts: 2
Joined: 09 Mar 2011, 09:11

How to create a generic Java .net (C#) protocol?

Postby heinrich_soebke » 18 Mar 2011, 12:58

What is a working (and recommended) way to create a protocol (the communication) between a Java SFS extension and a Unity3D client?
There should be transferred Java objects without adding any code to serialize and deserialize these objects (so that new java objects can be added without changing the protocol)

One approach so far: usage of IKVM on Unity3D, so the Java classes can be used in Unity3D also. But what is a solution for the serialize/deserialize part? xStream? (although XML is costly in terms of bandwitdth?)

Any thoughts?
Posts: 2
Joined: 09 Mar 2011, 09:11

Postby heinrich_soebke » 22 Mar 2011, 15:24

Got an answer:
Use SFS2X.
There exists on both sides (Java and C#) a Serializer/Deserializer for a raw protocol.

Code: Select all

       public void TestObjectNestedClass() {
          DefaultSFSDataSerializer serializer = DefaultSFSDataSerializer.Instance;
          DefaultSFSDataSerializer.RunningAssembly = Assembly.GetExecutingAssembly();
         ISFSObject sfsObj = new SFSObject();
         TestObject obj1 = new TestObject();
         obj1.intField = 60;
         TestObject obj2 = new TestObject();
         obj2.intField = 70;
         sfsObj.PutClass("obj1", obj1);
          sfsObj.PutClass("obj2", obj2);
          ByteArray data = serializer.Object2Binary(sfsObj);
          Assert.Greater(data.Length, 0);
          ISFSObject res = serializer.Binary2Object(data);
          Assert.AreEqual(2, res.Size());
          TestObject res1 = res.GetClass("obj1") as TestObject;
          TestObject res2 = res.GetClass("obj2") as TestObject;
          Assert.AreEqual(60, res1.intField);
          Assert.AreEqual(70, res2.intField);

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 2 guests