I'm want to transferring data from client to server and from server to client;
Transfer data from client to server is is successful.
But i' dont have transfer data from server to client.
From example a'm add code in this sourse:
viewtopic.php?t=11123&highlight=getclass
thank Whiskey =)
for this server:
I'm receive data class. And send his to client.
Code: Select all
public class serializetestHandler extends BaseClientRequestHandler {
@Override
public void handleClientRequest(User player, ISFSObject params)
{
Test test = (TestObject) params.getClass("test");
this.send("SerializetestHandler received class, id: " + test.getId(), new SFSObject(), player);
SFSObject ansver = new SFSObject();
TestObject rObj = new TestObject();
rObj.setName("I'ts work");
rObj.setId(44);
ansver.putClass("test", rObj);
this.send("receiveCmd", ansver, player);
}
}
client receiver:
Code: Select all
public void OnExtensionResponse(BaseEvent evt)
{
DefaultSFSDataSerializer serializer = DefaultSFSDataSerializer.Instance;
DefaultSFSDataSerializer.RunningAssembly = Assembly.GetExecutingAssembly();
string cmd = (string)evt.Params["cmd"];
SFSObject sfsParameters = (SFSObject)evt.Params["params"];
Debug.Log("receive: " + cmd);
if (cmd == "receiveCmd")
{
try
{
object obj = sfsParameters.GetClass("test");
if (obj == null) Debug.LogWarning("is null");
else Debug.LogWarning(((TestObject)obj).getName());
}
catch (Exception ex)
{
Debug.LogWarning(ex.Message);
}
}
}
But i'm get to exception "Cannot cast from source type to destination type."
What's wrong?
And I'm add [Serializable] attribute to data class:
Code: Select all
using System;
using Sfs2X.Protocol.Serialization; // to serialize classes
namespace nl.inthere.sfs2x.serialization
{
[Serializable]
public class TestObject : SerializableSFSType
{
public TestObject() { }
public String name;
public int id;
public string getName()
{
return name;
}
public void setName(string name)
{
this.name = name;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public string GetJavaPackageName()
{
return "nl.inthere.sfs2x.serialization";
}
}
}