{"id":16367250,"url":"https://github.com/nyxcode/tcp4k","last_synced_at":"2025-06-12T13:07:38.709Z","repository":{"id":106460475,"uuid":"94344149","full_name":"NyxCode/TCP4K","owner":"NyxCode","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-18T11:04:36.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-10T00:54:19.126Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NyxCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2017-06-14T15:09:33.000Z","updated_at":"2017-06-14T15:13:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"f88446de-721e-4bf7-9a9e-2d1817bb4c19","html_url":"https://github.com/NyxCode/TCP4K","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NyxCode/TCP4K","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyxCode%2FTCP4K","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyxCode%2FTCP4K/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyxCode%2FTCP4K/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyxCode%2FTCP4K/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NyxCode","download_url":"https://codeload.github.com/NyxCode/TCP4K/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyxCode%2FTCP4K/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259470949,"owners_count":22862998,"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":[],"created_at":"2024-10-11T02:49:11.724Z","updated_at":"2025-06-12T13:07:38.690Z","avatar_url":"https://github.com/NyxCode.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TCP4K\nTCP4K is a tiny library in Kotlin for designing packet-based application protocols for networking applications.\nIt's **performant** and **extremely simple** to use.\n\n## Example\n\nPlease take a look at the directory TCP4K/chat-example - It's a small, working chat application based on TCP4K.\n\n```kotlin\nval server_config = Server.ServerConfig(port = 1234)\nval server = Server.create(server_config)\n\nserver.handler.register\u003cMyPacket\u003e { connection, myPacket -\u003e\n    // A client has send a packet of type 'MyPacket'\n}\n\n...\n\nval client_config = Client.ClientConfig(host = \"localhost\", port = 1234)\nval client = Client.create(client_config)\n\nclient.handler.register\u003cConnectionEstablishedEvent\u003e { connection, event -\u003e \n    val message = MyPacket(...)\n    connection.send(message)\n}\n```\n\n## Documentation\nTCP4K is based on listeners. Once you have created a server/client, you can register listener for specific messages\nby optaining the 'ListenerHandler' of the server/client and invoking the 'register' method. You can also register listener\nfor events. Currently, 'ConnectionEstablishedEvent', 'ConnectionClosedEvent' and 'ConnectionExceptionEvent' are supported.\nIn a listener, you can access the connection through which the message came and the actual message.\n\n```kotlin\nval connection = ...\nconnection.send(...)    // sends a packet to the client\nconnection.close(...)   // closes the connection\nconnection[key] = value // stores data \"in\" the connection.\nconnection[key]         // gets data previously stored under 'key'\nconnection.open         // is this connection open \u0026 usable?\n\nval client = ...\nclient.connection       // the connection to the server (may be null)\nclient.connected        // is the client connected to a server?\nclient.config           // the configuration of this client\nclient.handler          // the listenerhandler of this client\nclient.connect()        // connects to the server specified in the configuration\nclient.disconnect()     // disconnects from the server\nclient.send(...)        // sends a message to the server (= client.connection.send(...))\nclient.synchronize()    // Blocks the current thread until the connection to the server is closed\n\nval server = ...\nserver.config           // the configuration of this server\nserver.handler          // the listenerhandler of this server\nserver.connections      // all open connections\nserver.start()          // starts this server\nserver.stop()           // stops this server\nserver.broadcast()      // broadcasts a message to all clients\nserver.synchronize()    // Blocks the current thread until the server is stopped\n...\n\n// creates a listener for a specific packet\nval listener = object: Listener\u003cMyPacket\u003e { ... }                       \nval listener = Listener\u003cMyPacket\u003e { connection, myPacket -\u003e ... }     \n\nval handler = ...\n// registers the given listener\nhandler.register(MyPacket::class, myListener)                           \nhandler.register\u003cMyPacket\u003e(myListener) \nhandler.register(myListener)\nhandler.register\u003cMyPacket\u003e { connection, myPacket -\u003e ... }\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyxcode%2Ftcp4k","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnyxcode%2Ftcp4k","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyxcode%2Ftcp4k/lists"}