Not getting onConnected callback

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

Moderators: Lapo, Bax

Trixer
Posts: 5
Joined: 12 Sep 2016, 01:30

Not getting onConnected callback

Postby Trixer » 05 Oct 2016, 04:24

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 () {
   
   }
}
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Not getting onConnected callback

Postby Lapo » 05 Oct 2016, 08:10

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
Lapo
--
gotoAndPlay()
...addicted to flash games
Trixer
Posts: 5
Joined: 12 Sep 2016, 01:30

Re: Not getting onConnected callback

Postby Trixer » 06 Oct 2016, 02:22

I bet that fixes it! Thanks a bunch!


*Edit*

Yep sure did! Thanks alot for your help!

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 32 guests