SocketJack 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SocketJack --version 1.2.0
                    
NuGet\Install-Package SocketJack -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SocketJack" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SocketJack" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SocketJack" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SocketJack --version 1.2.0
                    
#r "nuget: SocketJack, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SocketJack@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SocketJack&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SocketJack&version=1.2.0
                    
Install as a Cake Tool

SocketJack

SocketJack is a high-performance, flexible networking library for .NET, designed to simplify the creation of robust client-server and peer-to-peer (P2P) applications. It provides a modern, extensible API for TCP and WebSocket communication, advanced serialization, and seamless P2P networking with metadata-driven peer discovery.


Features

  • Unified TCP & WebSocket Support
    Easily create clients and servers using TCP or WebSockets with a consistent API.

  • Peer-to-Peer (P2P) Networking
    Built-in P2P support allows direct peer connections, peer discovery, and metadata sharing.

    • Peers are identified, discovered, and described using The Identifier class w/metadata.
    • Host and client roles are managed automatically.
    • Peer redirection and relay are supported for NAT traversal scenarios AND typical centralized configurations.
  • Advanced Serialization

    • Serializer interface (ISerializer) with a fast, efficient JSON implementation.
    • Custom converters for complex types (e.g., Bitmap).
    • Type whitelisting/blacklisting for secure deserialization.
  • Efficient Data Handling

    • Large buffer support (default 1MB) for high-throughput scenarios.
    • Asynchronous, non-blocking I/O for scalability.
    • Optimized for .NET Standard 2.1, .NET 6, .NET 8, and .NET 9.
  • Metadata-Driven Peer Management

    • Attach arbitrary metadata to peers and connections.
    • Query and filter peers by metadata for dynamic discovery and routing.
  • Extensible Event System

    • Events for connection, disconnection, peer updates, and data receipt.
    • Customizable handling for peer redirection and connection requests.
  • Security & Control

    • SSL/TLS support for secure connections.
    • Fine-grained control over allowed types and connection policies.

Peer-to-Peer Implementations

SocketJack's P2P system is designed for flexibility and ease of use:

  • Peer Discovery:
    Use metadata to find peers with specific attributes (e.g., game lobbies, chat rooms).

  • Direct Peer Connections:
    Peers can connect directly, bypassing the server when possible for low-latency communication.

  • Peer Redirection:
    If a direct connection is not possible, messages can be relayed through other peers or the server.

  • Host/Client Role Management:
    The library automatically manages which peer acts as host or client, simplifying connection logic.

  • Metadata Propagation:
    Metadata changes are propagated to all connected peers, enabling dynamic network topologies.


Efficiency

  • High Throughput:
    Large default buffer sizes and efficient serialization minimize overhead.

  • Asynchronous Operations:
    All networking is fully async, allowing thousands of concurrent connections.

  • Minimal Allocations:
    Serialization and deserialization are optimized to reduce memory usage and GC pressure.

  • Selective Serialization:
    Only allowed types are serialized/deserialized, improving security and performance.


Possible Usages

SocketJack is ideal for a wide range of networking scenarios, including:

  • Real-Time Multiplayer Games
    Fast, low-latency communication between players with dynamic peer discovery.

  • Distributed Chat Applications
    Peer-to-peer chat with metadata-driven room discovery and direct messaging.

  • IoT Device Networks
    Efficient, secure communication between devices with flexible topology.

  • Remote Control & Automation
    Secure, event-driven control of remote systems with custom data types.

  • Custom Protocols & Services
    Build your own protocols on top of TCP/WebSocket with full control over serialization and peer management.


Getting Started

  1. Install via NuGet:
   Install-Package SocketJack
  1. Create a Server:
   var server = new TcpServer(port: 12345);
   server.StartListening();
  1. Connect a Client:
   var client = new TcpClient();
   await client.Connect("127.0.0.1", 12345);
  1. Sending and Receiving:
   client.Send("Hello, Server!");
   server.OnReceived += (sender, args) => {
       var message = args.Object as string;
       // Handle message
   };
  1. Setting up callbacks:
// Register a callback for a custom class
server.RegisterCallback<CustomClass>((peer, customClassObject) =>
{
    Console.WriteLine($"Received: customClassObject");

    // Echo back to the client
    peer.Send("10-4");
});
  1. Enabling options by default: MUST be called before the instantiation of a Client or Server.
   TcpOptions.Default.UsePeerToPeer = true;
  1. Attach Metadata: This will ONLY work on the server authority. Use your own authentication to validate the clients.
   client.Identifier.SetMetaData(client, "Room", "Lobby1");

Documentation


License

SocketJack is open source and licensed under the MIT License.


Contributing

Contributions, bug reports, and feature requests are welcome!
See CONTRIBUTING.md for details.


SocketJack � Fast, flexible, and modern networking for .NET.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net6.0-windows7.0 is compatible.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SocketJack:

Package Downloads
SocketJack.NewtonsoftJson

An Implementation of Newtonsoft.Json for SocketJack

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0.92925 0 9/29/2025
1.2.0 117 9/24/2025
1.1.0.1 54 8/2/2025
1.0.3 150 7/4/2025
1.0.2.60100 176 6/1/2025