{"id":15035943,"url":"https://github.com/sniper5000/networks","last_synced_at":"2025-04-09T23:20:47.157Z","repository":{"id":250244515,"uuid":"833906601","full_name":"Sniper5000/NetWorks","owner":"Sniper5000","description":"C# Networking library with encryption support (RSA + AES), allowing developers to quickly setup a server and client. with Unity IL2CPP support.","archived":false,"fork":false,"pushed_at":"2024-09-11T05:32:47.000Z","size":88,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T01:11:23.034Z","etag":null,"topics":["aes","client","csharp-library","encryption-decryption","multithreading","networking","rsa","server","tcp","udp","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sniper5000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"sniper5000"}},"created_at":"2024-07-26T02:41:23.000Z","updated_at":"2024-09-11T05:32:50.000Z","dependencies_parsed_at":"2025-02-21T07:31:32.607Z","dependency_job_id":null,"html_url":"https://github.com/Sniper5000/NetWorks","commit_stats":null,"previous_names":["sniper5000/networks"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sniper5000%2FNetWorks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sniper5000%2FNetWorks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sniper5000%2FNetWorks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sniper5000%2FNetWorks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sniper5000","download_url":"https://codeload.github.com/Sniper5000/NetWorks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126271,"owners_count":21051894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","client","csharp-library","encryption-decryption","multithreading","networking","rsa","server","tcp","udp","unity"],"created_at":"2024-09-24T20:29:48.234Z","updated_at":"2025-04-09T23:20:47.107Z","avatar_url":"https://github.com/Sniper5000.png","language":"C#","funding_links":["https://ko-fi.com/sniper5000","https://ko-fi.com/A0A110TLP9'"],"categories":[],"sub_categories":[],"readme":"# NetWorks\nC# Networking library with encryption support, allowing developers to quickly setup a server and client. with Unity IL2CPP support.\n\n## Installation\n1. Download the source code or .dll\n2. Add a reference on your C# project for NetWorks.dll\n3. Verify by using NetWorks\n```\nusing NetWorks.Network;\n```\n\n\n## Quick Start [WIP]\n\n### Client\nTo quickly create a custom client, inherit BaseClient and override BaseClient methods with your own.\n\n```\nusing NetWorks.Network;\n\nclass EventedClient : BaseClient\n{\n    public event Action? OnClientReady;\n    public event Action? OnClientLeave;\n    public event Action\u003cbyte[], NetworkProtocol, bool\u003e? OnDataReceive;\n\n    //When the client has successfully connected to the server.\n    public override void ClientReady()\n    {\n        OnClientReady?.Invoke();\n    }\n    //When the client disconnects or lost connection, this will fire.\n    public override void ClientLeave()\n    {\n        OnClientLeave?.Invoke();\n    }\n    //data = byte[] to send to the connected server\n    //protocol = determines the whether TCP, UDP should be used to send\n    //IsEncrypted = whether this data should be encrypted(AES + RSA) before sending or not.\n    public override void DataReceived(byte[] data, NetworkProtocol protocol, bool IsEncrypted = false)\n    {\n        OnDataReceive?.Invoke(data, protocol, IsEncrypted);\n    }\n}\n```\nInstantiate your client, and connect to your server program by providing it an IP \u0026 Port\n```\n//Example\nvar Client = new EventedClient(); //Change it to your custom client class.\nTask.Run(() =\u003e \n{ \n    Client.Connect(\"127.0.0.1\", 7777); \n});\n```\nOnce the client is ready, data can be sent by using\n```\n//Client will send the byte[] using the protocol specified and encryption (if true)\nClient.Send(Data, protocol, encrypted); //Data is a byte[], protocol (NetworkProtocol.TCP or NetworkProtocol.UDP), Encrypted (true or false)\n```\n\n### Server\nTo create a custom server, inherit from BaseServer and override BaseServer methods with your own.\n```\nusing NetWorks.Network;\n\nclass EventedServer : BaseServer\n{\n    public event Action\u003cServerClient\u003e? OnClientReady;\n    public event Action\u003cServerClient\u003e? OnClientLeave;\n    public event Action\u003cServerClient, byte[], NetworkProtocol, bool\u003e? OnDataReceive;\n\n    //When a client has successfully connected, this will be fired.\n    //client = client that has connected.\n    public override void ClientReady(ServerClient client)\n    {\n        OnClientReady?.Invoke(client);\n    }\n    //When a client has disconnected, this will be fired.\n    //client = client that has disconnected.\n    public override void ClientLeave(ServerClient client)\n    {\n        OnClientLeave?.Invoke(client);\n    }\n    //When data has been fully received from a client, this will be fired.\n    //client = client that sent the data\n    //data = byte[] received\n    //protocol = TCP or UDP\n    //IsEncrypted = Whether the data received was encrypted with AES + RSA\n    public override void DataReceived(ServerClient client, byte[] data, NetworkProtocol protocol, bool IsEncrypted)\n    {\n        OnDataReceive?.Invoke(client, data, protocol, IsEncrypted);\n    }\n}\n```\nInstantiate your server and run the listener on another thread. (Otherwise the main thread will hang)\n```\n//Example\nvar Listener = new EventedServer(); //Change it to your custom server class.\nTask.Run(() =\u003e Listener.Run(\"127.0.0.1\", 7777));\n```\nNote: NetWorks runs on multiple threads, as such methods fired by NetWorks will not be running on the main thread.\n\n## Examples\n\nAll standalone examples using NetWorks library can be found here: \nhttps://github.com/Sniper5000/NetWorks/tree/main/NetWorks%20Library\n\n## Unity\nNote: NetWorks runs on multiple threads, as such methods fired by NetWorks will not be running on the main thread.\n1. Download NetWorks Standard 2.1 source code or NetWorks(Unity) DLL for both Server \u0026 Client.\n    NetWorks Standard 2.1: https://github.com/Sniper5000/NetWorks/tree/main/NetWorks%20Standard%202.1\n2. Drag the .dll or source code to your Unity project.\n3. Start using NetWorks.\n\nIf it's required to run a method on the main thread from an event fired by NetWorks.\n\nCreate a C# Monobehaviour script, Use a custom name or the one used below \"RunMainThread\"\n```\nusing System.Collections.Concurrent;\nusing System;\nusing UnityEngine;\n\n//If you have used a custom name, change the class name to your custom one\npublic class RunMainThread : MonoBehaviour\n{\n    private static ConcurrentQueue\u003cAction\u003e RunOnMainThread = new();\n\n    // Either FixedUpdate or Update will work\n    void Update()\n    {\n        if (!RunOnMainThread.IsEmpty)\n        {\n            lock (RunOnMainThread)\n            {\n                while (RunOnMainThread.TryDequeue(out var action))\n                {\n                    action?.Invoke();\n                }\n            }\n        }\n    }\n\n    /// \u003csummary\u003e\n    /// Runs \u003csee cref=\"Action\"/\u003e on the Main Thread.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"action\"\u003eAction to execute\u003c/param\u003e\n    public static void Enqueue(Action action)\n    {\n        RunOnMainThread.Enqueue(action);\n    }\n}\n```\nAfter the script is done, drag it into an empty GameObject. (Keep only 1 instance active)\n\nTo run a method on the main thread use\n```\nRunMainThread.Enqueue(() =\u003e SomeMethod());\n```\n\n[WIP]: Missing Unity examples and additional documentation.\n\n\n\u003ca href='https://ko-fi.com/A0A110TLP9' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsniper5000%2Fnetworks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsniper5000%2Fnetworks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsniper5000%2Fnetworks/lists"}