{"id":25879876,"url":"https://github.com/httpmarco/netline","last_synced_at":"2025-03-02T13:29:16.738Z","repository":{"id":262903160,"uuid":"886922565","full_name":"HttpMarco/netline","owner":"HttpMarco","description":"A simple and lightweight network library for Java.","archived":false,"fork":false,"pushed_at":"2025-01-11T12:30:01.000Z","size":292,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T13:35:17.380Z","etag":null,"topics":["client","netty5","networking","server"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HttpMarco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2024-11-11T21:13:21.000Z","updated_at":"2024-12-03T20:39:48.000Z","dependencies_parsed_at":"2025-01-02T11:23:31.715Z","dependency_job_id":"22ce559b-d783-418b-b6a4-f6830adb2fb5","html_url":"https://github.com/HttpMarco/netline","commit_stats":null,"previous_names":["httpmarco/netline"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HttpMarco%2Fnetline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HttpMarco%2Fnetline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HttpMarco%2Fnetline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HttpMarco%2Fnetline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HttpMarco","download_url":"https://codeload.github.com/HttpMarco/netline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241512626,"owners_count":19974619,"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":["client","netty5","networking","server"],"created_at":"2025-03-02T13:29:15.724Z","updated_at":"2025-03-02T13:29:16.722Z","avatar_url":"https://github.com/HttpMarco.png","language":"Java","readme":"\u003cp align=\"center\"\u003e\n     \u003ch3 align=\"center\"\u003eNetLine\u003c/h3\u003e\n     \u003cp align=\"center\"\u003eA simple and lightweight network library for Java.\u003c/p\u003e\n\u003c/p\u003e\n\n## Dependency\nThe libs are hosted on the Sonatype Nexus Repository. You can add the following dependency to your project.\n\n### 0.1 Maven\n```xml\n\u003crepository\u003e\n    \u003cid\u003enetline-central-snapshot\u003c/id\u003e\n    \u003curl\u003ehttps://s01.oss.sonatype.org/content/repositories/snapshots/\u003c/url\u003e\n\u003c/repository\u003e\n\n\u003cdependency\u003e\n    \u003cgroupId\u003edev.httpmarco\u003c/groupId\u003e\n    \u003cartifactId\u003enetline\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### 0.2 Gradle\n```groovy\nmaven {\n    url = uri(\"https://s01.oss.sonatype.org/content/repositories/snapshots/\")\n}\n\ncompile \"dev.httpmarco:netline:1.0.0-SNAPSHOT\"\n```\n\n### 0.3 Gradle Kotlin DSL\n```kotlin\nmaven(\"https://s01.oss.sonatype.org/content/repositories/snapshots/\")\n\nimplementation(\"dev.httpmarco:netline:1.0.0-SNAPSHOT\")\n```\n\n## 1. Generell\n\n### 1.1 Create a new comp component\nBelow is an example of a simple server component. The API is similar for a client or, in the future, a node.\n```java\nNet.line()\n    // Set the type of the component.\n    // You can also use: client or, in the future, a node.\n    .server()\n    // If you want to configure your component, you can do the following:\n    .config(it -\u003e {\n        // Set the hostname for binding. The default is '0.0.0.0'.\n        it.hostname(\"xx.xx.xx.xx\");\n        // Set the port for binding. The default is '9091'.\n        it.port(1234);\n    })\n    // Register a new channel tracking. See the tracking table for more details.\n    .track(YourExamplePacket.class, (channel, packet) -\u003e {\n        // Add your logic here when 'YourExamplePacket' is received.\n        System.out.println(\"Packet received! Hello!\");\n    });\n```\n\n### 1.2 Request and Response\nWith Netline, you can easily send a request packet to a component (comp) and receive a response. This can be used either asynchronously or synchronously.\n```java\n// For every request, you need a responder to handle the request and send back a response. \n// You can create it as follows:\n// Important: The request ID and responder ID must match for each request-response pair!\nserver.responderOf(\"your_custom_request_id\", (channel, id) -\u003e new ResponsePacketType());\n\nvar request = client.request(\"your_custom_request_id\", ResponsePacketType.class);\n\n// Get the response of your request synchronously.\n// The default timeout limit is 5 seconds. You can customize this in your component configuration.\nResponsePacketType response = request.sync();\n\n// The same request but handled asynchronously.\nrequest.async().whenComplete((result, throwable) -\u003e {\n    if (throwable != null) {\n        // The request failed. You must check the cause of the exception!\n        throwable.printStackTrace();\n        return;\n    }\n    // The request was successfully answered.\n    ResponsePacketType asyncResponse = result;\n});\n```\n### 1.3 Broadcast from client\n```java\n// send a packet to all clients and servers\nclient.generateBroadcast().send(new YourBroadcastPacket());\n\n// send a packet only to selected clients\nclient.generateBroadcast()\n    .to(\"clientA\", \"clientB\")\n    .send(new YourBroadcastPacket());\n\n// send a packet to all, but skip a specific client(s). Here 'clientA'\nclient.generateBroadcast()\n    .exclude(\"clientA\")\n    .send(new YourBroadcastPacket());\n\n// send a packet to all clients and servers, but also to his own client\nclient.generateBroadcast()\n    .generateBroadcast()\n    .send(new YourBroadcastPacket());\n\n// send a packet to the first 2 endpoints. Left clients are be ignored!\nclient.generateBroadcast()\n    .limt(2)\n    .send(new YourBroadcastPacket());\n\n// All this options can be merged together in one broadcast option.\n// Important: All options are optional! \nclient.generateBroadcast()\n    .limit(10) // maximum client amount \n    .exclude(\"trash-service\") // ignore the trash services\n    .to(\"rich-service\", \"babo-service\") // we select the best services\n    .deselect(Receiver.SERVER) // send only to all clients\n    .send(new YourBroadcastPacket()); // finally sending the broadcast\n```\n\n### 1.4 Redirect packets\nYou can send a packet from a client connected to the server, routing it through the server to a specific client. In this example, the packet is sent to client A.\n```java\nclient.send(\"clientA\", new YourRedirectPacket());\n```\n\n## 2. Custom comp \n\n### 2.1 Custom client comp methods\n```java\nvar client = Net.line().client();\n\n```\n\n### 2.2 Custom server comp methods\n```java\nvar server = Net.line().server();\nserver.bootSync();\n// alert a packet to all connected clients\nserver.broadcast(new YourPacketType());\n// alert a packet to a specific client\nserver.send(\"clientA\", new YourPacketType());\n// alert a packet to all clients with an id starting with \"stats\"\nserver.send(it -\u003e it.id().startWith(\"stats\"), new YourPacketType());\n// get all connected clients\nserver.clients();\n```\n\n## 3. Security\n\n### 3.1 Blacklist and Whitelist\n```java\nvar server = Net.line().server();\nserver.config(it -\u003e {\n    // blacklist a specific address\n    it.blacklist().add(\"xx.xx.xx.xx\");\n    // whitelist a specific address \n    it.whitelist().add(\"xx.xx.xx.xx\");\n});\nserver.bootSync();\n```\n\n### 3.2 Custom security adapter\nThe security provider allow you, to manage your clients with a custom security policy. Block or allow clients, based on your custom logic. A simpler way are the blacklist and whitelist. \n```java\n// set your custom security provider -\u003e child of @SecurityProvider\nserver.withSecurityPolicy(new YourCustomSecurityProvider());\n```\nExample of a simple security provider:\n```java\npublic class YourCustomSecurityProvider implements SecurityProvider {\n\n    @Override\n    public void detectUnauthorizedAccess(NetChannel netChannel) {\n        // alert if a client tries to connect without permission\n        // Channel closed automatically after this method.\n        System.err.println(\"Unauthorized access detected\");\n    }\n\n    @Override\n    public boolean authenticate(NetChannel netChannel) {\n        // check the id of the client. Here you can implement your custom logic.\n        return netChannel.id().equals(\"testA\");\n    }\n}\n```\n\n## 4.0 Your own cluster\n\n\n\n## 5.0 Tracking table\n\n| Tracking                         | Description                                                                 |\n|----------------------------------|-----------------------------------------------------------------------------|\n| ClientConnectedTracking.class    | If the client connects to the server, this tracking will be triggered.      |\n| ClientDisconnectedTracking.class | If the client disconnects from the server, this tracking will be triggered. |\n\n\n## 6.0 Future features :)\n- [ ] Node implementation\n- [ ] test for bad response answer\n- [ ] Add a better packet base logic\n- [ ] message channels\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttpmarco%2Fnetline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttpmarco%2Fnetline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttpmarco%2Fnetline/lists"}