High-performance, fully managed .NET networking library for TCP, UDP, and WebSocket communication. Features built-in peer-to-peer with NAT traversal, pluggable System.Text.Json serialization, SslStream TLS 1.2 encryption, GZip/Deflate compression, bandwidth throttling. Send any object across a unified, transport-agnostic API. Targets .NET Standard 2.1, .NET 8
$ dotnet add package SocketJackSocketJack 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.
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.
Advanced Serialization
ISerializer) with a fast, efficient JSON implementation.Bitmap).Efficient Data Handling
Metadata-Driven Peer Management
Extensible Event System
Security & Control
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.
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.
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.
Install-Package SocketJack
var server = new TcpServer(port: 12345);
server.StartListening();
var client = new TcpClient();
await client.Connect("127.0.0.1", 12345);
client.Send("Hello, Server!");
server.OnReceived += (sender, args) => {
var message = args.Object as string;
// Handle message
};
// 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");
}); TcpOptions.Default.UsePeerToPeer = true;
client.Identifier.SetMetaData(client, "Room", "Lobby1");
SocketJack is open source and licensed under the MIT License.
Contributions, bug reports, and feature requests are welcome!
See CONTRIBUTING.md for details.
SocketJack � Fast, flexible, and modern networking for .NET.