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

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

manoj_sahu
Posts: 6
Joined: 11 Aug 2011, 03:22
Location: Gurgaon
Contact:

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

Postby manoj_sahu » 18 Oct 2011, 10:58

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 + ">)");
}
}
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 18 Oct 2011, 11:55

You need to enable processing the events by doing :

Code: Select all

void FixedUpdate () {
    smartFox.ProcessEvents ();
}
manoj_sahu
Posts: 6
Joined: 11 Aug 2011, 03:22
Location: Gurgaon
Contact:

Postby manoj_sahu » 19 Oct 2011, 01:56

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.
manoj_sahu
Posts: 6
Joined: 11 Aug 2011, 03:22
Location: Gurgaon
Contact:

Postby manoj_sahu » 19 Oct 2011, 03:32

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.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 7 guests