Page 1 of 1

Not getting onConnected callback

Posted: 05 Oct 2016, 04:24
by Trixer
My server log shows a valid connection but for some reason its not firing a callback (or any callback for that matter). Any reason this might be? I am using an extremely simple connector script.

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Sfs2X;
using Sfs2X.Util;
using Sfs2X.Logging;
using Sfs2X.Core;
using System;

public class Connector : MonoBehaviour {
    private string defaultHost = "127.0.0.1";
    private int defaultTcpPort = 9933;
    private int defaultWsPort = 8888;
    private SmartFox sfs;

    public Text StatusTextBox;

    // Use this for initialization
    void Start () {
        StatusTextBox.text = "Connecting....";
        sfs = new SmartFox();

        // Set ThreadSafeMode explicitly, or Windows Store builds will get a wrong default value (false)
        sfs.ThreadSafeMode = true;

        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

        sfs.AddLogListener(LogLevel.INFO, OnInfoMessage);
        sfs.AddLogListener(LogLevel.WARN, OnWarnMessage);
        sfs.AddLogListener(LogLevel.ERROR, OnErrorMessage);

        ConfigData cfg = new ConfigData();
        cfg.Host = defaultHost;
        cfg.Port = defaultTcpPort;
        cfg.Zone = "BasicExamples";
        cfg.Debug = true;

        // Connect to SFS2X
        sfs.Connect(cfg);

    }

    private void OnErrorMessage(BaseEvent evt)
    {
        throw new NotImplementedException();
    }

    private void OnWarnMessage(BaseEvent evt)
    {
        throw new NotImplementedException();
    }

    private void OnInfoMessage(BaseEvent evt)
    {
        throw new NotImplementedException();
    }

    private void OnConnectionLost(BaseEvent evt)
    {
        StatusTextBox.text = "Connection Lost";
    }

    private void OnConnection(BaseEvent evt)
    {
        if ((bool)evt.Params["success"])
        {
            StatusTextBox.text = "connected";
        }
        else
        {
            StatusTextBox.text = "failed";
        }
    }

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

Re: Not getting onConnected callback

Posted: 05 Oct 2016, 08:10
by Lapo
Hi,
if you set ThreadSafeMode=true then you will need to manually call the ProcessEventQueue() in the Update method. Otherwise all events will remain in the event queue.

Cheers

Re: Not getting onConnected callback

Posted: 06 Oct 2016, 02:22
by Trixer
I bet that fixes it! Thanks a bunch!


*Edit*

Yep sure did! Thanks alot for your help!