Skip to content

alec1o/Netly

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Netly

powered by ALEC1O
netly logo
About

Netly is a flexible socket library built on c-sharp. It is compatible with (Android, iOS, Linux, Windows...)


Documentation

Netly docs (HERE)


Install

Official publisher

Nuget Unity Asset Store
Install on Nuget Install on Asset Store

Sponsor and Supporter

Well, this project is open source and only development can be supported by suggestions for improvements, bug reports or the like. (for those who want to financially support this resource is not available at this time)


Versions

Notable changes

v1 (old) v2 (stable) v3 (in dev) v4 (nonexistent)
TCP (client/server) TCP/IP Message Framing TLS/SSL (client/server) Websocket (client/server)
UDP TCP/UDP performance improvement Include docs/sample (SSL/TLS) Include docs/sample (Websocket)
Message Framing memory and performance improve
Message Framing new protocol
UDP impl connection with udp (ping/timeout)
collaborative documentation docsify
Byter 2.0

List of tested platforms

Feature

Below are some missing features that are planned to be added in later versions.

  • SSL/TLS (v3)
  • Websocket (v4)

Dependency

Build
Build dependencies
Build step-by-step
# 1. clone repository 
$ git clone "https://github.com/alec1o/netly" netly/

# 2. build netly project
$ dotnet build -C Release netly/
  # DLL_PATH: netly/src/bin/netstandard2.0/Netly.dll

# 3. For use Netly.dll you need Byter.dll (a Netly dependecy)
$ git clone "https://github.com/alec1o/byter" byter/

# 4. build byter project
$ dotnet build -C Release byter/
  # DLL_PATH: byter/src/bin/netstandard2.0/Byter.dll

# WARNING: when use Netly.dll must include Byter.dll  

Demo

TcpClient Syntax

using Netly;
using Netly.Core;

var client = new TcpClient(framing: true);

// Enable SSL/TLS (onValidate delegate is optional)
client.UseEncryption(enableEncryption: true, onValidate: null);

client.OnOpen(() => 
{
    // client connected
});

client.OnClose(() =>
{
    // client disconnected
});

client.OnError((Exception exception) =>
{
    // connection close because: 1.Error on connecting, 2.Invalid framing data
});

client.OnData((byte[] data) =>
{
    // raw data received
});

client.OnEvent((string name, byte[] data) =>
{
    // event received (event use netly protocol) 
});

client.OnModify((Socket socket) =>
{
    // you can modify socket, called before open connection
});

client.Open(new Host("127.0.0.1", 8080));

TcpServer Syntax

using Netly;
using Netly.Core;

var server = new TcpServer(framing: true);

// Enable SSL/TLS
byte[] pfxCert = <DO_SOMETHING>;
string pfxPass = <DO_SOMETHING>;

server.UseEncryption(pfxCert, pfxPass, SslProtocols.Tls13); // TLS v1.3

server.OnOpen(() => 
{
    // server start listen
});

server.OnClose(() =>
{
    // server stop listen
});

server.OnError((Exception exception) =>
{
    // error on start listen (connecting)
});

server.OnData((TcpClient client, byte[] data) =>
{
    // a client receive raw data
});

server.OnEvent((TcpClient client, string name, byte[] data) =>
{
    // a client receive event (event use netly protocol)
});

server.OnEnter((TcpClient client) =>
{
    // a client connected on server
    
    client.OnClose(() =>
    {
        // alternative of: TcpServer.OnClose
    });
    
    client.OnData(() =>
    {
        // alternative of: TcpServer.OnData
    });
    
    client.OnEvent(() =>
    {
        // alternative of: TcpServer.OnEvent
    });
});

server.OnExit((TcpClient client) =>
{
    // a client disconnected from server
});

server.OnModify((Socket socket) =>
{
    // you can modify socket, called before listen and bind a port 
});

server.Open(new Host("127.0.0.1", 8080));