Skip to content

emanuel-v-r/socket.io-client-csharp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket.IO-client for .NET

An elegant socket.io client for .NET, Supports .NET Standard 2.0.

Build Status NuGet

How to use

Wiki

Breaking changes in 2.2.4

Before SocketIOClient v2.2.4, the default EIO is 3, which works with socket.io v2.x, in SocketIOClient v2.2.4, the default EIO is 4, which works with socket.io v3.x and v4.x

Breaking changes in 2.2.0

SocketIOClient v2.2.0 makes System.Text.Json the default JSON serializer. If you'd like to continue to use Newtonsoft.Json, add the SocketIOClient.Newtonsoft.Json NuGet package and set your JsonSerializer to NewtonsoftJsonSerializer on your SocketIO instance. System.Text.Json is faster and uses less memory.

Continue to use Newtonsoft.Json

var client = new SocketIO("http://localhost:11000/");
client.JsonSerializer = new NewtonsoftJsonSerializer(client.Options.EIO);

Custom JsonSerializerOptions/System.Text.Json

class MyJsonSerializer : SystemTextJsonSerializer
{
    public MyJsonSerializer(int eio) : base(eio) {}

    public override JsonSerializerOptions CreateOptions()
    {
        var options = new JsonSerializerOption();
        options.PropertyNameCaseInsensitive = true;
        return options;
    }
}

// ...

var client = new SocketIO("http://localhost:11000/");
client.JsonSerializer = new MyJsonSerializer(client.Options.EIO);

Custom JsonSerializerSettings/Newtonsoft.Json

class MyJsonSerializer : NewtonsoftJsonSerializer
{
    public MyJsonSerializer(int eio) : base(eio) {}

    public override JsonSerializerSettings CreateOptions()
    {
        return new JsonSerializerSettings
        {
            ContractResolver = new global::Newtonsoft.Json.Serialization.DefaultContractResolver
            {
                NamingStrategy = new global::Newtonsoft.Json.Serialization.CamelCaseNamingStrategy()
            },
            Formatting = Formatting.Indented
        };
    }
}

// ...

var client = new SocketIO("http://localhost:11000/");
client.JsonSerializer = new MyJsonSerializer(client.Options.EIO);

Development

Before development or testing, you need to install the nodejs.

# start socket.io v2 server
cd src/socket.io-server-v2
npm i # If the dependencies are already installed, you can ignore this step.
npm start

# start socket.io v3 server
cd src/socket.io-server-v3
npm i # If the dependencies are already installed, you can ignore this step.
npm start

Change log

SocketIOClient

Sponsors

About

socket.io-client implemention for .NET

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 89.2%
  • JavaScript 8.3%
  • HTML 1.9%
  • Other 0.6%