Not Handling SFSEvents

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

Moderators: Lapo, Bax

DixiE
Posts: 3
Joined: 03 Dec 2021, 01:52

Not Handling SFSEvents

Postby DixiE » 03 Dec 2021, 16:12

I have been having some trouble getting a basic .NET client to connect to a server. I can call SmartFox.Connect and see on the server that a new session has been created, but my event listener for SFSEvent.CONNECTION is never called. If I sleep the thread for a second and then send a followup login request, I get no error and can see on the server there's a successful login but - again - neither my SFSEvent.LOGIN nor SFSEvent.LOGIN_ERROR listeners get called.

I wrote a tiny script in Unity that exhibits the same problems. Additionally I dispatch a custom event just to see if the dispatcher itself is the problem, but that seems to succeed so the problem is something different:

Code: Select all

public class Client : MonoBehaviour
{
    SmartFox sfs;

    void Start()
    {
        sfs = new SmartFox();
   
        // Add event listeners
        sfs.AddEventListener(SFSEvent.CONNECTION, (evt) => Debug.Log("Connection"));
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, (evt) => Debug.Log("Connection Lost"));
        sfs.AddEventListener("test", (evt) => Debug.Log("Test"));

        // Dispatch custom event
        sfs.Dispatcher.DispatchEvent(new BaseEvent("test"));

        // Connect
        ConfigData cfg = new ConfigData() {
            Host = "127.0.0.1",
            Port = 9933,
            Zone = "TestZone",
        };
        sfs.Connect(cfg);

        Debug.Log("Finished init");
    }
}


The output from this code is:

Code: Select all

Test
Finished init


And the server logs:

Code: Select all

15:59:44,194 INFO  [main] v2.SmartFoxServer     - Boot sequence starts...
15:59:44,378 INFO  [main] core.SFSEventManager     - SFSEventManager initialized
15:59:44,387 INFO  [main] impl.DefaultFileReplicator     - Using "/tmp/vfs_cache" as temporary files store.
15:59:44,413 INFO  [main] v2.SmartFoxServer     - License loaded:

==========================================
LICENSE DETAILS
------------------------------------------
Type            : Community Edition
Max users       : 100
==========================================

15:59:44,414 INFO  [main] managers.SFSBannedUserStorage     - BanUserStorage initialized
15:59:44,419 INFO  [main] managers.SFSBannedUserManager     - BanUser data loaded: 0 records.
15:59:44,421 INFO  [main] v2.SmartFoxServer     - Protocol Type is: BINARY
15:59:44,422 INFO  [main] config.DefaultConfigLoader     - Loading: zones/BasicExamples.zone.xml
15:59:44,433 INFO  [main] config.DefaultConfigLoader     - Loading: zones/TestZone.zone.xml
15:59:44,441 INFO  [main] managers.SFSZoneManager     -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: BasicExamples
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

15:59:44,452 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: BasicExamples }, [ Room: The Lobby, Id: 0, Group: default, isGame: false ], type = SFSRoom
15:59:44,453 INFO  [main] managers.SFSZoneManager     -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: TestZone
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

15:59:44,456 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: --=={{{ AdminZone }}}==-- }, [ Room: AdminRoom, Id: 1, Group: default, isGame: false ], type = SFSRoom
15:59:44,475 INFO  [main] core.AdminToolService     - AdminTool Service started
15:59:44,496 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - Listening Sockets: { 0.0.0.0:9933, (Tcp) } { 127.0.0.1:9933, (Udp) }
15:59:44,496 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     -
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_|
[ 2.17.0 ]

15:59:44,496 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.17.0) READY!
15:59:45,428 INFO  [TomcatRunner] bluebox.BBSessionFilter     - BlueBox Service (4.0.2) READY.
16:00:11,737 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:52830 } on Server port: 9933 <---> 52830


I'm running on Arch Linux, but will test on Windows later today and update this thread with my findings. My server version is 2.17.0, and I'm using the 1.7.16 client API. I was using .NET 6.0 initially, but tried with .NET 4.5 (the lowest version compatible with the client API) and the problem remained the same.

EDIT: Can confirm I get the same experience on Windows with Unity.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Not Handling SFSEvents

Postby Lapo » 04 Dec 2021, 05:50

Hi,
if you're developing a non-Unity client you need to configure the SmartFox.ThreadSafe property before connecting.
http://docs2x.smartfoxserver.com/api-do ... 122431.htm

In other words use this:

Code: Select all

var client = new SmartFox();
SmartFox.ThreadSafe = false;


Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: Google [Bot] and 25 guests