giraffesyo / socket.io-client-csharp

socket.io-client implemention for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Socket.IO-client for .NET

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

Build Status NuGet

How to use

Wiki

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
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

License:MIT License


Languages

Language:C# 89.4%Language:HTML 4.8%Language:TypeScript 3.3%Language:JavaScript 1.5%Language:CSS 0.9%Language:Dockerfile 0.1%Language:PowerShell 0.0%