How can I connect unity to my smart fox server plugin

I followed a tutorial and had that working but I made a few changes to try and experiment to see how it works but I cant get it to work properly. Right now I tried to edit it so that it would send coordinates to the server and the server would send them back. But I get this error from the server.
if you comment to help or try to give a answer I well make sure to thumb it up

alt text

if you cant read it open the picture URL to get a larger image Piclair - Screenshot sharing

Here is the NetBeans project script

 package PlayerPosExtension;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class PlayerPos extends BaseClientRequestHandler{

    @Override
    public void handleClientRequest(User user, ISFSObject objIn) {
      
       int x = objIn.getInt("x");
       int y = objIn.getInt("y");
       int z = objIn.getInt("z");
       
       ISFSObject objOut = new SFSObject();
       objOut.putInt("PosX", x);
       objOut.putInt("PosY", y);
       objOut.putInt("PosZ", z);
       
       send("PosX", objOut, user);
       send("PosY", objOut, user);
       send("PosZ", objOut, user);
    }
    
}

Here is the script in unity

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities;
using Sfs2X.Entities.Data;

public class SFS2X_Connect : MonoBehaviour 
{
public string ConfigFile = "Network/sfs-config.xml";
public bool UseConfigFile = false;
public string ServerIP = "127.0.0.1";
public int ServerPort = 9933; 
public string ZoneName ="BasicExamples"; 
public string UserName = "hi";
public string RoomName = "Lobby";

SmartFox sfs; 

	void Start()
	{
		sfs = new SmartFox(); 
		sfs.ThreadSafeMode = true; 
		
		sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
		sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
		sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLogin);
		sfs.AddEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, OnConfigLoad);
		sfs.AddEventListener(SFSEvent.CONFIG_LOAD_FAILURE, OnConfigFail);
		sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnJoinRoom);
		sfs.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnJoinRoomError);
		sfs.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
		sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); 
		
		if(UseConfigFile)
		{
			sfs.LoadConfig(Application.dataPath + "/" + ConfigFile);
		}
		else
			{
			 	sfs.Connect(ServerIP, ServerPort); 
			}

		sfs.Connect(ServerIP, ServerPort);
	}

	void OnConfigLoad(BaseEvent e)
	{
		Debug.Log("Config File Loaded");
		sfs.Connect(sfs.Config.Host, sfs.Config.Port);
	}

	void OnJoinRoom(BaseEvent e)
	{
		Debug.Log("Joined Room: " + e.Params["room"]);
		sfs.Send(new PublicMessageRequest("Hello world"));
	}	
	
	void OnPublicMessage(BaseEvent e)
	{
		Room room = (Room)e.Params["room"];
		User sender = (User)e.Params["sender"];
		Debug.Log("[" + room.Name + "] " + sender.Name + ": " + e.Params["message"]);
	}

	void OnJoinRoomError(BaseEvent e)
	{
		Debug.Log("JoinRoom Error (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
	}

	void OnConfigFail(BaseEvent e)
	{
		Debug.Log("Failed to load Config File");
	}

	void OnLogin(BaseEvent e)
	{
		Debug.Log("Loggged in: " + e.Params["user"]);
		sfs.Send(new JoinRoomRequest(RoomName));

		ISFSObject objOut = new SFSObject();
		objOut.PutInt("x", 2);
		objOut.PutInt("y", 5);
		objOut.PutInt("z", 1);

		sfs.Send(new ExtensionRequest("PosX", objOut));
		sfs.Send(new ExtensionRequest("PosY", objOut));
		sfs.Send(new ExtensionRequest("PosZ", objOut));
	}
	
	void OnExtensionResponse(BaseEvent e)
	{
		string cmd = (string)e.Params["cmd"];
		ISFSObject objIn = (SFSObject)e.Params["params"];
		
	
		Debug.Log("x :" + objIn.GetInt("PosX"));
		Debug.Log("y :" + objIn.GetInt("PosY"));
		Debug.Log("z :" + objIn.GetInt("PosZ"));
		
	}
	
	void OnLoginError(BaseEvent e)
	{
		Debug.Log("Loggged error: (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
	}
	
	void OnConnection(BaseEvent e)
	{
		if((bool)e.Params["success"])
		{
			Debug.Log("Successfully Connected");
			if(UseConfigFile)
			{		
				ZoneName = sfs.Config.Zone; 
			}	
			sfs.Send(new LoginRequest(UserName, "",ZoneName));
		}
		else
		{
			Debug.Log("Connection Failed"); 
		}
	}
	
	void Update()
	{
		sfs.ProcessEvents(); 
	}

	
	void OnApllicationQuit()
	{
		if(sfs.IsConnected)
			sfs.Disconnect();
	}

	void OnGUI()
	{
		
	}
}

I’ve been working with SmartFox + Unity3D for over 3 years now, and I can tell you matter-of-factly that your problem is on the Server’s end, not in Unity, although your Unity script is going to cause triple the needed bandwidth.

I don’t mean to be blunt, but you’re doing a lot of things wrong in these scripts. For example:

 ISFSObject objOut = new SFSObject();
 objOut.PutInt("x", 2);
 objOut.PutInt("y", 5);
 objOut.PutInt("z", 1);
 
 sfs.Send(new ExtensionRequest("PosX", objOut));
 sfs.Send(new ExtensionRequest("PosY", objOut));
 sfs.Send(new ExtensionRequest("PosZ", objOut));

You’re packing your x,y,z coordinates into a single a SFSObject and sending it to the server three times… you only need to send it once since all three coordinates are included with each send.

Your SFS Server is failing when it boots because your extension is not implementing the basic SmartFox Server functionality at all, so it has no idea what to do with the data you are sending to it.

I’m not sure what sort of game you are working on and what you want to accomplish with these scripts, but I think you would be much better off reverting your extension to the original Basic Examples and working from there. If you’re building an MMO, start with the MMO example… if you’re building an FPS, they have an example for that as well.

Smartfox has a hell of a learning curve when it comes to custom extensions. They can be relatively easy to implement, but ridiculous when it comes to debugging due to the lack of good examples (and a community that is nowhere near as helpful as Unitys). And to top it off, a lot of the examples take short-cuts that make the system seem as though it’s doing what they claim, when really the information is being fudged ( the Space-themed MMO project is a perfect example of this; they claim that it uses their MMOAPI, but when you break it down it’s been fudged and things like Area-of-Interest aren’t actually programmed to work… they just look like they work for the sake of the demo. That’s not say that AOI in SmartFox MMO rooms doesn’t work at all, it’s just that the projects they offer as examples aren’t going to a be a legit “how-to”).

My best advice it read everything they have available on their site, and do so multiple times. Take lots of notes, but keep in mind that not all of their example code works (I’ve found at least 2 cases of example scripts in their tutorials section that don’t work at all… reported them both a long time ago, neither have been fixed).

I’m not trying to discourage you from SmartFox at all, I’m just saying that there are pretty much two cases here:

  1. Go with the example extension that best suits your needs and build from there, or
  2. if you’re dead-set on building your own custom extension, put in the time to learn how smartfox works. Build simple, stupid extensions that do basic things and add on them.

Last but not least, as awesome as the Unity Community is, this isn’t a place for SmartFox issues… SmartFox has their own forum for that, but I have only experienced crickets and accusations (from Mods themselves) there… everything I’ve done has been through absolute stubbornness and more man hours than I dare count. In fact, I assisted them once with an issue concerning their Windows 8 dlls; at first I was crucified by a Mod, then I proved I was right, and then the thread disappeared)

I’d be happy to offer you help along the way, but only after you’ve put in the time to learn the basics of how it works. Based off of your server extension code, you need to put a lot more time into reading the documentation and becoming more familiar with the API.

It’s a crappy, lonely, pull-your-hair-out frustrating ride, but the rewards are pretty substantial :slight_smile: If you give me an idea of what sort of project you are planning to make, I’d be more than happy to let you know which example project would be best to start out with… it may seem pretty obvious on the face of it, but you’d be surprised at how many corners they cut in their example scenes. Both the basic MMO and the SpaceMMO examples use the MMOAPI, but both cut substantial corners in different ways, so depending on what you hope to do with the game, one will probably be much better suited than the other.