Page 1 of 1

Unable to connect to SFS from C# (noob quest).

Posted: 18 Oct 2011, 10:58
by manoj_sahu
Hi,
I am trying to connect to smart-fox from my Unity.
but except to 'Connecting' i didnt see anything.
obviously i am using SFS dll, my sfs is running and able to access my localhost/sfs-admin panel. also no erro/info from unity.

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Requests;
using Sfs2X.Logging;
public class SmartFoxConnector : MonoBehaviour {

// Use this for initialization
private SmartFox _smartFox;
public string serverIP = "127.0.0.1";
public int serverPort = 9339;
void Start () {


}

// Update is called once per frame
void Update () {

}
void Awake()
{
Application.runInBackground = true;
_smartFox = new SmartFox(true);
_smartFox.AddEventListener(SFSEvent.CONNECTION, onConnectToSmartFoxServer);
_smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, onConnectionLost);
_smartFox.Connect(serverIP, serverPort);
}
public void onConnectionLost(BaseEvent evt)
{
Debug.Log("Connecting");
}
public void onConnectToSmartFoxServer(BaseEvent evt)
{
bool success = (bool)evt.Params["success"];
string error = (string)evt.Params["errorMessage"];

Debug.Log("On Connection callback got: " + success + " (error : <" + error + ">)");
}
}

Posted: 18 Oct 2011, 11:55
by appels
You need to enable processing the events by doing :

Code: Select all

void FixedUpdate () {
    smartFox.ProcessEvents ();
}

Posted: 19 Oct 2011, 01:56
by manoj_sahu
appels wrote:You need to enable processing the events by doing :

Code: Select all

void FixedUpdate () {
    smartFox.ProcessEvents ();
}



Thanks for the help, it works fine, but now new problem -

Connection error: No connection could be made because the target machine actively refused it.

i dont have any idea about the error, however i am well versed with ActionScript3 + java + SmartFox.

the same code in as3 is working fine, but my machine is refusing for only Unity's Connection.

Posted: 19 Oct 2011, 03:32
by manoj_sahu
manoj_sahu wrote:
appels wrote:You need to enable processing the events by doing :

Code: Select all

void FixedUpdate () {
    smartFox.ProcessEvents ();
}



Thanks for the help, it works fine, but now new problem -

Connection error: No connection could be made because the target machine actively refused it.

i dont have any idea about the error, however i am well versed with ActionScript3 + java + SmartFox.

the same code in as3 is working fine, but my machine is refusing for only Unity's Connection.




problem solved, i was using wrong port (9339 instead of 9933).

thanks for the help @appels once again.