Disconnection on calling toJson() for SFSObject

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

suvroz
Posts: 12
Joined: 16 Mar 2010, 09:37

Disconnection on calling toJson() for SFSObject

Postby suvroz » 06 Dec 2012, 14:12

I am trying to call toJson() on SFSObject in the dispatch method of my class (which implements IEventListener):

Code: Select all

@Override
public void dispatch(BaseEvent event) throws SFSException {
    if (event.getType().equalsIgnoreCase(SFSEvent.EXTENSION_RESPONSE))
    {
        ISFSObject params = (ISFSObject) eventArgs.get("params");
        if (params.getUtfString("Request").equalsIgnoreCase("GAME_START_COUNTDOWN_END"))
        {
            Log.e("control reaches here");         
            String jsonParam = params.toJson();
            //TODO do something
        }
    }
}


The log saying "control reaches here" gets printed when I get a message from the server. However if I have the "toJson" call, the client gets disconnected with the following warning/error messages:

12-06 19:03:33.362: W/System.err(16362): 39774 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnDisconnect to 1 listeners
12-06 19:03:33.362: W/System.err(16362): 39781 [Thread-15] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: net.sf.json.JSONObject
12-06 19:03:33.362: W/System.err(16362): 39782 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event OnError to 1 listeners
12-06 19:03:33.362: W/System.err(16362): 39782 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event disconnect to 1 listeners
12-06 19:03:33.372: W/System.err(16362): 39783 [Thread-15] INFO sfs2x.client.core.EventDispatcher - Dispatching event connectionLost to 1 listeners


if I remove the "toJson" line, there is no disconnection. Has anyone faced similar problems? Can anyone please help understand and fix this issue?

We are using Server version 2.4.0 and Client API version 1.0.5 (both latest available for download as of now).
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection on calling toJson() for SFSObject

Postby Lapo » 10 Dec 2012, 14:34

Thanks for reporting we will take a look as soon as possible
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection on calling toJson() for SFSObject

Postby Lapo » 12 Dec 2012, 10:01

UPDATE:
the problem is that the JSON conversion is not implemented/supported in the client API.
The toJSON() method is a legacy coming from the Server side version of the SFSObject but it's never used on the client side, so we didn't include the JSON library which would only make the API heavier.

We recommend using the binary codec by calling toBinary() and newFromBinary() methods

thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 18 guests