All Projects → PauSabatesC → SockNet

PauSabatesC / SockNet

Licence: Apache-2.0 License
The easiest and fastest way to work with sockets in C#

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to SockNet

Abot
Cross Platform C# web crawler framework built for speed and flexibility. Please star this project! +1.
Stars: ✭ 1,961 (+4569.05%)
Mutual labels:  netcore, netcore2, netcore3
socketwrapper
Async/Sync networking library including UDP, TCP and TLS/TCP socket classes written in C++ 17.
Stars: ✭ 33 (-21.43%)
Mutual labels:  socket, asynchronous, socket-programming
Terminal
All-in-one solution for the management and security of your Telegram group. This is the third version and is written in C#
Stars: ✭ 12 (-71.43%)
Mutual labels:  netcore, netcore3
NModbus4.NetCore
Simply NModbus4 but targeting .NET instead of .NET Framework
Stars: ✭ 25 (-40.48%)
Mutual labels:  netcore, netcore3
EasySharpFrame
Easy .NET Develop Frame.
Stars: ✭ 73 (+73.81%)
Mutual labels:  socket, netcore
sockerl
Sockerl is an advanced Erlang/Elixir socket framework for TCP protocols and provides fast, useful and easy-to-use API for implementing servers, clients and client connection pools.
Stars: ✭ 26 (-38.1%)
Mutual labels:  socket, socket-programming
Ubiety.Xmpp.Core
XMPP library for .NET Core
Stars: ✭ 32 (-23.81%)
Mutual labels:  nuget, netcore2
jQuery-datatable-server-side-net-core
A simple Visual Studio solution using jQuery DataTable with Server-Side processing using .NET 5
Stars: ✭ 71 (+69.05%)
Mutual labels:  netcore2, netcore3
MQTTnet
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
Stars: ✭ 3,309 (+7778.57%)
Mutual labels:  nuget, netcore
asynchronous
A D port of Python's asyncio library
Stars: ✭ 35 (-16.67%)
Mutual labels:  socket, asynchronous
Extended-Toolkit
A companion toolkit for the standard toolkit.
Stars: ✭ 83 (+97.62%)
Mutual labels:  nuget, netcore
DDNRuntime-examples
DDNRuntime(Delphi .NET Framework/.NET Core Runtime) example. DDNRuntime is a library for Delphi to call .net dll. Support the assembly written by c#, vb.net. Support importing .net dll to delphi, can create .net wrapper automatically.
Stars: ✭ 15 (-64.29%)
Mutual labels:  netcore, netcore2
TinyChat
💬 Extra small chat client with GUI
Stars: ✭ 15 (-64.29%)
Mutual labels:  socket, socket-programming
workerman
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.4.
Stars: ✭ 10,005 (+23721.43%)
Mutual labels:  socket, asynchronous
aioudp
Asyncio UDP server
Stars: ✭ 21 (-50%)
Mutual labels:  socket, asynchronous
net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (-50%)
Mutual labels:  socket, nuget
AspSqliteCache
An ASP.NET Core IDistributedCache provider backed by SQLite
Stars: ✭ 39 (-7.14%)
Mutual labels:  nuget, netcore
letportal
Angular 9 .NET Core 3.1 open source web portal platform 2020 for building quickly application form, data grid , data list, chart, report, users management
Stars: ✭ 29 (-30.95%)
Mutual labels:  netcore, netcore3
dark-sky-core
A .NET Standard Library for using the Dark Sky API.
Stars: ✭ 55 (+30.95%)
Mutual labels:  nuget, netcore
SQLiteEncryptionUsingEFCore
SQLite Encryption using Entity Framework Core (EFCore)
Stars: ✭ 42 (+0%)
Mutual labels:  netcore, netcore2

SockNet logo

The easiest and fastest way to work with sockets in C#

CodeFactor Codacy Badge Nuget Build status Nuget

This library is a wrapper of common tcp and network streams libaries in order to act as a more high-level and developer friendly api to deal with socket communications.

Installation

Nuget

dotnet add package SockNet

Supported Runtimes

Windows Linux Mac OS X
.NET Framework v4.6+ n/a n/a
.NET Standard .NET Standard 2.0+
.NET Core v2.0+

If you want to get the latest development build: Build status


Features

🚀 Production ready library. Forget to waste time testing buffers and tcp framing communication, we cover you.

🧵 Asynchronous connections and write/read petitions.

📚 Developer friendly API with many method overloads to satisfy all user use cases.

🎭 Client and/or Server sockets creation. Use it just for your .Net client or for both client and server!

Why?

Working with sockets with C# can be really overwhelming due to its different libraries and many methods to choose from.

For example you have to deal with TcpClient, NetworkStream, TcpListener classes with really similar methods between them, but with different purposes, and within each class there are different ways to achieve the same goal.

So you end up searching in the internet and official documentation every time you need to work with sockets but you don't know which of the many solutions you found is the more correct,fully asynchronous, production ready and newer option.

Usage example

Client socket

To create a client socket connection you only need these methods:

Initializes the client indicating the server address:

  var client = new SocketClient("127.0.0.1", 80);

Sends and receive data asynchronously once its connected:

  if (await client.Connect())
  {
      await client.Send("Am I cool?");
      var recData = await client.ReceiveBytes();
  }

Server socket

To create a socket server listening asynchronously to many petitions and able to response them:

Initialization of the server:

  var server = new SocketServer();
  server.InitializeSocketServer("127.0.0.1", 80);
  server.SetReaderBufferBytes(1024);
  server.StartListening();

Sends and receive data once its connected:

  if(server.IsNewData())
  {
      var data = server.GetData();
      // Do whatever you want with data
      Task.Run(() => DoSomething(data, server));
  }

Send data back to the client:

  server.ResponseToClient(data.Key, "this is cool!");

FAQ: But how the receive method works? What if I have a custom socket message with delimitators for instance?

Both socket and client have different methods to achive that, and the goal is to keep adding as much as possible to satisfy all common uses cases.

For instance you can set the server to receive data with these methods:

// Sets the server to receive an unknown number of bytes. Reads data until it stops receiving.
SetReaderBytes();
SetReaderBufferBytes(int bufferSize);

// Sets the server to receive the specified number of bytes
SetReaderNumberOfBytes(int bufferSize, int numberBytesToRead);

//Sets the receiver to get the tcp data telegram. Reads from the start delimitator until the end delimitator is reached.
SetReaderBytesWithDelimitators(byte[] startDelimitator, byte[] endDelimitator);
SetReaderBytesWithEndDelimitator(byte[] endDelimitator);

//... more to be added!!

Documentation

The API expose to different interfaces: ISocketClient and ISocketServer.

Both are xml documented so Visual Studio Intellisense will explain each method and parameter, as well as its different method overloads options. Nevertheless, you can see it here and here.

Ready to try example

Client

  byte[] recData = null;
  SocketClient client = new SocketClient("127.0.0.1", 9999);
  try
  {
      if (await client.Connect())
      {
          await client.Send("this is a test");
          recData = await client.ReceiveBytes();
      }
      Console.WriteLine("Received data: " + Encoding.UTF8.GetString(recData));
  }
  catch(Exception e)
  {
      Console.WriteLine("Exception raised: " + e);
  }
  //...
  client.Disconnect();

Server

  var socketServer = new SocketServer();
  socketServer.InitializeSocketServer("127.0.0.1", 9999);
  socketServer.SetReaderBufferBytes(1024);
  socketServer.StartListening();

  bool openServer = true;
  while (openServer)
  {
      if(socketServer.IsNewData())
      {
          var data = socketServer.GetData();
          // Do whatever you want with data
          Task.Run(() => DoSomething(data, socketServer));
      }
  }

  //.... 
  socketServer.CloseServer();


  private static void DoSomething(KeyValuePair<TcpClient, byte[]> data, SocketServer server)
  {
    Console.WriteLine(((IPEndPoint)data.Key.Client.RemoteEndPoint).Address.ToString() + ": " + Encoding.UTF8.GetString(data.Value));
    server.ResponseToClient(data.Key, "received");
  }

Contribute!

Feel free to contribute! Submit your pull requests, report issues or propose new features!

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