OnExtensionResponse Question with Unity and XML

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

Moderators: Lapo, Bax

Posts: 61
Joined: 16 Jan 2009, 14:48

OnExtensionResponse Question with Unity and XML

Postby matrix211v1 » 07 Aug 2009, 17:03

Hello All:

I don't have a clue what I am doing. Here is my issue:

Code: Select all

function handleRequest(cmd, params, user, fromRoom)
   // Add your code here

        if (cmd == "getData")
                trace("handleRequest inside")
            // create a SQL statement
                var sql = "SELECT remoteUserID FROM characterData where name = '"+params["remoteUserName"]+"'"
                // execute query on DB
                // queryRes is a ResultSet object
                var queryRes = dbase.executeQuery(sql)

            // prepare the response object
                var response = {}
                response._cmd = "getData"
                // Here we create an array for storing the database data
                response.db = []
                if (queryRes != null)
                        // Cycle through all records in the ResultSet
                        for (var i = 0; i < queryRes.size(); i++)
                                // Get a record
                                var tempRow = queryRes.get(i)
                                // This object will hold the record data that we'll send to the client
                                var item = {}
                                // From the record object we can get each field value
                                item.remoteUserID       = tempRow.getItem("remoteUserID")
                               trace("item.remoteUserID: "+item.remoteUserID)                               
                                response.db.push( item )
                   trace("DB Query failed")
                _server.sendResponse(response, -1, null, [user])

This runs and get the data from the database. It's all good and I have tested it, and the traces are showing the correct data.

Then the OnExtensionResponse gets fired.

Code: Select all

   public void OnExtensionResponse(object data, string type)
      Debug.Log("NetworkController : OnExtensionResponse");
      Debug.Log("Type: "+type);
      // Handle XML responses
      if (type == SmartFoxClient.XTMSG_TYPE_XML)
         SFSObject responseData = (SFSObject)data;
         Debug.Log("Testing Return Data: "+responseData.GetString("_cmd"));
         switch (responseData.GetString("item"))
            case "getData":
               Debug.Log("I hit 1");

            case "remoteUserID":
               Debug.Log("I hit 2");
         // TODO: check command and perform required actions

      // Handle RAW responses
      else if (type == SmartFoxClient.XTMSG_TYPE_STR)
         string responseData = (string)data;
         // TODO: check command and perform required actions


All I want to do is get the value of "remoteUserID". Is there a way to dump the entire SFSObject in a Debug so I can see what's going on?

But otherwise, I think everything else is working. I know if I do a responseData.GetString("_cmd") I will get back "getData". But I cannot seem to get the value of "remoteUserID" back.

What am I overlooking? Thanks for any and all help!
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 08 Aug 2009, 07:42

The Util/SFSObjectSerialization class has some code in the bottom that is commented for dumping an SFSObject.

Remove the comments and you should be able to use those to see whats really inside the SFSObject

Otherwise its hard to help without seeing what you send/receive and what the output of your code is.


Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 2 guests