H.Socket.IO 1.2.7

Install-Package H.Socket.IO -Version 1.2.7
dotnet add package H.Socket.IO --version 1.2.7
<PackageReference Include="H.Socket.IO" Version="1.2.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add H.Socket.IO --version 1.2.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: H.Socket.IO, 1.2.7"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install H.Socket.IO as a Cake Addin
#addin nuget:?package=H.Socket.IO&version=1.2.7

// Install H.Socket.IO as a Cake Tool
#tool nuget:?package=H.Socket.IO&version=1.2.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

H.Socket.IO

Language License Requirements Requirements Build Status

High-performance event-based .NET Socket.IO library with a convenient interface,
aimed at writing the smallest possible code on the user side.

Features:

  • Supports the latest version of Socket.IO server
  • Supports namespaces
  • The library is null-free and does not contain NRE
  • Event-based
  • Completely asynchronous

Nuget

NuGet NuGet NuGet

Install-Package H.Socket.IO

Usage

using System;
using System.Threading.Tasks;
using H.Socket.IO;

#nullable enable

public class ChatMessage
{
    public string? Username { get; set; }
    public string? Message { get; set; }
    public long NumUsers { get; set; }
}
	
public async Task ConnectToChatNowShTest()
{
    await using var client = new SocketIoClient();

    client.Connected += (sender, args) => Console.WriteLine($"Connected: {args.Namespace}");
    client.Disconnected += (sender, args) => Console.WriteLine($"Disconnected. Reason: {args.Reason}, Status: {args.Status:G}");
    client.EventReceived += (sender, args) => Console.WriteLine($"EventReceived: Namespace: {args.Namespace}, Value: {args.Value}, IsHandled: {args.IsHandled}");
    client.HandledEventReceived += (sender, args) => Console.WriteLine($"HandledEventReceived: Namespace: {args.Namespace}, Value: {args.Value}");
    client.UnhandledEventReceived += (sender, args) => Console.WriteLine($"UnhandledEventReceived: Namespace: {args.Namespace}, Value: {args.Value}");
    client.ErrorReceived += (sender, args) => Console.WriteLine($"ErrorReceived: Namespace: {args.Namespace}, Value: {args.Value}");
    client.ExceptionOccurred += (sender, args) => Console.WriteLine($"ExceptionOccurred: {args.Value}");
    
    client.On("login", () =>
    {
        Console.WriteLine("You are logged in.");
    });
    client.On("login", json =>
    {
        Console.WriteLine($"You are logged in. Json: \"{json}\"");
    });
    client.On<ChatMessage>("login", message =>
    {
        Console.WriteLine($"You are logged in. Total number of users: {message.NumUsers}");
    });
    client.On<ChatMessage>("user joined", message =>
    {
        Console.WriteLine($"User joined: {message.Username}. Total number of users: {message.NumUsers}");
    });
    client.On<ChatMessage>("user left", message =>
    {
        Console.WriteLine($"User left: {message.Username}. Total number of users: {message.NumUsers}");
    });
    client.On<ChatMessage>("typing", message =>
    {
        Console.WriteLine($"User typing: {message.Username}");
    });
    client.On<ChatMessage>("stop typing", message =>
    {
        Console.WriteLine($"User stop typing: {message.Username}");
    });
    client.On<ChatMessage>("new message", message =>
    {
        Console.WriteLine($"New message from user \"{message.Username}\": {message.Message}");
    });
	
    await client.ConnectAsync(new Uri("wss://socketio-chat-h9jt.herokuapp.com/"));

    await client.Emit("add user", "C# H.Socket.IO Test User");

    await Task.Delay(TimeSpan.FromMilliseconds(200));

    await client.Emit("typing");

    await Task.Delay(TimeSpan.FromMilliseconds(200));

    await client.Emit("new message", "hello");

    await Task.Delay(TimeSpan.FromMilliseconds(200));

    await client.Emit("stop typing");

    await Task.Delay(TimeSpan.FromSeconds(2));

    await client.DisconnectAsync();
}

Namespaces

// Will be sent with all messages(Unless otherwise stated).
// Also automatically connects to it.
client.DefaultNamespace = "my";

// or

// Connects to "my" namespace.
await client.ConnectAsync(new Uri(LocalCharServerUrl), namespaces: "my");
// Sends message to "my" namespace.
await client.Emit("message", "hello", "my");

Custom arguments

await client.ConnectAsync(new Uri($"wss://socketio-chat-h9jt.herokuapp.com/?access_token={mAccessToken}"));

Live Example

C# .NET Fiddle - https://dotnetfiddle.net/FWMpQ3
VB.NET .NET Fiddle - https://dotnetfiddle.net/WzIdnG
Http client of the tested Socket.IO server - https://socket-io-chat.now.sh/

Used documentation

Socket.IO Protocol - https://github.com/socketio/socket.io-protocol
Engine.IO Protocol - https://github.com/socketio/engine.io-protocol

Python implementation of Socket.IO - https://github.com/miguelgrinberg/python-socketio/blob/master/socketio/
Python implementation of Engine.IO - https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/

Contacts

NuGet packages (1)

Showing the top 1 NuGet packages that depend on H.Socket.IO:

Package Downloads
VL.SocketIO

SocketIO client plugin for VL. Wrapped around havendv' H.SocketIO nuget

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on H.Socket.IO:

Repository Stars
SaviorXTanren/mixer-mixitup
Streaming bot application for handling chat, events, moderation, and other streamer assistance features
Version Downloads Last updated
1.2.7 440 10/23/2021
1.2.6 124 10/21/2021
1.2.5 68 10/21/2021
1.2.4 72 10/21/2021
1.2.3 78 10/21/2021
1.2.1 627 7/15/2021
1.1.7.1 790 5/7/2021
1.1.7 8,177 1/11/2021
1.1.6 130 1/9/2021
1.1.5 146 1/9/2021
1.1.4 660 1/8/2021
1.1.3 165 1/4/2021
1.1.2 599 12/17/2020
1.1.1 1,911 12/9/2020
1.1.0 906 11/22/2020
1.0.4.1 3,862 8/23/2020
1.0.4 2,513 6/5/2020
1.0.3 274 6/3/2020
1.0.2 250 6/3/2020
1.0.1 192 6/3/2020
1.0.0.2 289 5/27/2020
1.0.0 216 5/27/2020
0.15.10 247 5/21/2020
0.15.9 281 5/21/2020
0.15.8 250 5/21/2020
0.15.7 205 5/21/2020
0.15.5 366 4/21/2020
0.15.4 212 4/21/2020
0.15.3 303 2/3/2020
0.15.2 232 2/2/2020
0.15.1 295 1/29/2020
0.15.0 282 1/29/2020
0.14.0 1,377 1/10/2020

⭐ Last 10 features:
- feat: To net6.0 and C# 10. 2021-10-21
- feat: Updated Newtonsoft.Json to 13.0.1. 2021-07-16
🐞 Last 10 bug fixes:
- fix: Fixed </br> in README. 2021-10-21
- fix: Fixed LocalTests. 2021-10-21
- fix: Fixed PackageReadmeFile. 2021-10-21