All Projects β†’ mrousavy β†’ GenericProtocol

mrousavy / GenericProtocol

Licence: MIT license
⚑️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to GenericProtocol

Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (+247.37%)
Mutual labels:  serialization, socket, tcp, protocol
Goridge
High-performance PHP-to-Golang IPC bridge
Stars: ✭ 950 (+2400%)
Mutual labels:  socket, tcp, sockets, binary
Bizsocket
εΌ‚ζ­₯socketοΌŒε―ΉδΈ€δΊ›δΈšεŠ‘εœΊζ™―εšδΊ†ζ”―ζŒ
Stars: ✭ 469 (+1134.21%)
Mutual labels:  socket, tcp, sockets
Binaryserializer
A declarative serialization framework for controlling formatting of data at the byte and bit level using field bindings, converters, and code.
Stars: ✭ 197 (+418.42%)
Mutual labels:  serialization, binary, protocol
EasyFileTransfer
An easy way to transfer file with any size on network with tcp protocol.
Stars: ✭ 30 (-21.05%)
Mutual labels:  socket, tcp, transfer
Ceras
Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
Stars: ✭ 374 (+884.21%)
Mutual labels:  serialization, binary, protocol
Socketify
Raw TCP and UDP Sockets API on Desktop Browsers
Stars: ✭ 67 (+76.32%)
Mutual labels:  socket, tcp, sockets
Bigq
Messaging platform in C# for TCP and Websockets, with or without SSL
Stars: ✭ 18 (-52.63%)
Mutual labels:  socket, tcp, sockets
Pypacker
πŸ“¦ The fastest and simplest packet manipulation lib for Python
Stars: ✭ 216 (+468.42%)
Mutual labels:  socket, tcp, protocol
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-47.37%)
Mutual labels:  serialization, binary, protocol
Fastbinaryencoding
Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift
Stars: ✭ 421 (+1007.89%)
Mutual labels:  serialization, binary, protocol
Ocaml Protoc
A Protobuf Compiler for OCaml
Stars: ✭ 129 (+239.47%)
Mutual labels:  serialization, protocol
Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (+244.74%)
Mutual labels:  serialization, binary
Hprose Js
Hprose is a cross-language RPC. This project is Hprose 2.0 RPC for JavaScript
Stars: ✭ 133 (+250%)
Mutual labels:  serialization, tcp
Chronicle Wire
A Java Serialisation Library that supports multiple formats
Stars: ✭ 204 (+436.84%)
Mutual labels:  serialization, binary
Coq Serapi
Coq Protocol Playground with Se(xp)rialization of Internal Structures.
Stars: ✭ 87 (+128.95%)
Mutual labels:  serialization, protocol
procbridge
A super-lightweight IPC (Inter-Process Communication) protocol over TCP socket.
Stars: ✭ 118 (+210.53%)
Mutual labels:  socket, protocol
surge
Simple, specialised, and efficient binary marshaling
Stars: ✭ 36 (-5.26%)
Mutual labels:  serialization, binary
Binary
Generic and fast binary serializer for Go
Stars: ✭ 86 (+126.32%)
Mutual labels:  serialization, binary
Hprose Html5
Hprose is a cross-language RPC. This project is Hprose 2.0 Client for HTML5
Stars: ✭ 237 (+523.68%)
Mutual labels:  serialization, tcp

<T>
Generic Protocol

⚑️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐

Buy Me a Coffee at ko-fi.com

Why?

Send whole objects over the net easier and faster

  1. Send nearly any .NET object (See: supported, custom) πŸ“¦
  2. Send/Receive faster by buffered send/receive and ZeroFormatter's fast (de-)serializing πŸ’¨
  3. Automatically correct errors with TCP and Auto-reconnect βœ…
  4. Async and Event based ⚑
  5. Efficient Network Discovery for other GenericProtocol Hosts πŸ”
  6. Fast binary links for file/images/.. transfer πŸ’Ύ
  7. Made with love ❀️

Sending objects:

await client.Send(someObject);

...on the other end:

private void MyMessageReceivedCallback(SomeObject someObject) {
  Console.WriteLine("I've received an object!");
}

How?

Add GenericProtocol to your existing .NET/.NET Core 2.0+/.NET Standard 2.0+ Project via NuGet:

PM> Install-Package GenericProtocol

Use the default namespace:

using GenericProtocol;

Are you connecting to a server, or are you the server?

Client

Connect to a server:

IClient client = await Factory.StartNewClient<MessageObject>("82.205.121.132", 1024, true);

The Factory will construct and connect a new IClient<T> object, where <T> is the object you want to send over the net (Here: MessageObject). This can be (supported) built in types (string, IEnumerable, ..) or custom types marked with [ZeroFormattable] (see here)

Send/Receive custom objects:

// MessageObject.cs
[ZeroFormattable]
public struct MessageObject {
  [Index(0)]
  public string Sender { get; set; }
  [Index(1)]
  public string Recipient { get; set; }
  [Index(2)]
  public string Message { get; set; }
  [Index(3)]
  public DateTime Timestamp { get; set; }
}

// Main.cs
IClient client = await Factory.StartNewClient<MessageObject>("82.205.121.132", 1024);
// MyMessageReceivedCallback will be called whenever this client receives a message
client.ReceivedMessage += MyMessageReceivedCallback; // void MyCallback(IPEndPoint, MessageObject)

var msgObject = new MessageObject() {
  Sender = "mrousavy",
  Recipient = "cbarosch",
  Message = "Hi server!",
  Timestamp = DateTime.Now
}
await client.Send(msgObject);
// (Optionally configure your Server so that it should redirect to the Recipient)
client.Dispose();

Send large binary content

IClient client = await Factory.StartNewBinaryDownlink("82.205.121.132", 1024, true);
client.Send(bytes); // bytes can be a large file for example
client.Dispose();

Use BinaryDownlinks/BinaryUplinks when you just want to send binary content (Files, Images, ..). The binary links will skip the serialization and send buffered right away.

Other

// Automatically try to reconnect on disconnects
client.AutoReconnect = true;
// Set the reading buffer size for incoming data
client.ReceiveBufferSize = 2048;
// Set the writing buffer size for outgoing data
client.SendBufferSize = 2048;
// Get the current Connection status
var status = client.ConnectionStatus;
// Connection to server lost handler
client.ConnectionLost += ...;

Server

Start a new server:

IServer server = await Factory.StartNewServer<MessageObject>(IPAddress.Any, 1024, true);

Send/Receive your objects (MessageObject in this example):

// Attach to the Message Received event
server.ReceivedMessage += MyMessageReceivedCallback; // void MyCallback(IPEndPoint, MessageObject)

var msgObject = new MessageObject() {
  Sender = "server",
  Recipient = "mrousavy",
  Message = "Hello client!",
  Timestamp = DateTime.Now
}
var clientEndPoint = server.Clients.First(); // Get first client in connected-clients enumerable
await server.Send(msgObject, clientEndPoint); // Send object to given client

Other

// Event once a client connects
server.ClientConnected += ...; // void ClientConnectedCallback(IPEndPoint)
// Event once a client disconnects
server.ClientDisconnected += ...; // void ClientDisconnectedCallback(IPEndPoint)
// Set the reading buffer size for incoming data
server.ReceiveBufferSize = 2048;
// Set the writing buffer size for outgoing data
server.SendBufferSize = 2048;
// Set the count of maximum clients to queue on simultanious connection attempts
server.MaxConnectionsBacklog = 8;

License: MIT | Contributing | Thanks!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].