New C# API v1.7.16 released

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

Moderators: Lapo, Bax

User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

New C# API v1.7.16 released

Postby Bax » 06 Oct 2021, 13:28

We just released v1.7.16 of the SFS2X C# client API for Unity / .Net / Mono / Universal Windows Platform.

This new version fixes a crash which could occur in Unity's Android build with il2cpp, due to a Console.WriteLine instruction in the API internal logger.

You can download the API at this url: https://www.smartfoxserver.com/download/sfs2x#p=client
Paolo Bax
The SmartFoxServer Team
DixiE
Posts: 3
Joined: 03 Dec 2021, 01:52

Re: New C# API v1.7.16 released

Postby DixiE » 03 Dec 2021, 02:03

Are the separate DotNet DLLs definitely free from the Unity dependency? Downloaded the client API today and wrote a simple test program that just connects to a server with some Console.WriteLines for logging, but I'm getting the following exception right after establishing my connection:

Code: Select all

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
   at Sfs2X.Logging.Logger.Log(LogLevel level, String message)
   at Sfs2X.Logging.Logger.Error(String[] messages)
   at Sfs2X.Bitswarm.BitSwarmClient.OnSocketData(Byte[] data)
   at Sfs2X.Core.ThreadManager.ProcessItem(Hashtable item)
   at Sfs2X.Core.ThreadManager.InThread()
   at System.Threading.Thread.StartCallback()


For reference, my csproj file is:

Code: Select all

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>disable</Nullable>
  </PropertyGroup>

  <ItemGroup>
      <Reference Include="SmartFox2X">
          <HintPath>../SFS2X/Debug/DotNet/SmartFox2X.dll</HintPath>
      </Reference>
  </ItemGroup>

</Project>


And the full program:

Code: Select all

using Sfs2X; // SmartFox
using Sfs2X.Core; // BaseEvent, SFSEvent
using Sfs2X.Util; // ConfigData

class Client {
    SmartFox sfs;

    public bool IsGood { get; private set; } = true;

    public static void Main() {
        Client client = new Client();
        while (client.IsGood) {
            Thread.Sleep(500);
        }
        Console.WriteLine("Exiting...");
    }
   
    public Client() {
        sfs = new SmartFox();
   
        // Add event listeners
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);

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

    ~Client() {
        if (sfs.IsConnected)
            sfs.Disconnect();
    }
   
    // Event Handlers
    private void OnConnection(BaseEvent evt) {
        if ((bool)evt.Params["success"]) {
            Console.WriteLine("Connection established successfully");
            Console.WriteLine("SFS2X API Version: " + sfs.Version);
        }
        else {
            Console.WriteLine("Connection failed");
            IsGood = false;
        }
    }
   
    private void OnConnectionLost(BaseEvent evt) {
        IsGood = false;
        Console.WriteLine("Connection lost: " + (string)evt.Params["reason"]);
    }
}


I don't actually see my event handlers' logs, but server-side I see a session get created and then immediately removed when I run the code.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: New C# API v1.7.16 released

Postby Bax » 03 Dec 2021, 14:47

It looks like we made a mistake creating the zip file for the download section of our website. We now fixed it.
Please download the C# API again. Sorry.
Paolo Bax
The SmartFoxServer Team
DixiE
Posts: 3
Joined: 03 Dec 2021, 01:52

Re: New C# API v1.7.16 released

Postby DixiE » 03 Dec 2021, 14:58

That solved it, thanks for the speedy fix!

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 25 guests