{"id":17055053,"url":"https://github.com/therolffr/miniserver","last_synced_at":"2025-08-20T22:49:42.980Z","repository":{"id":91419201,"uuid":"225002569","full_name":"TheRolfFR/miniServer","owner":"TheRolfFR","description":"Simplified Java TCP server. Can be used for multiplayer purposes, like games","archived":false,"fork":false,"pushed_at":"2021-04-27T08:14:16.000Z","size":183,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T12:43:45.885Z","etag":null,"topics":["beginner-friendly","java","multiplayer","multithreaded-server","multithreading","tcp","tcp-client","tcp-server","tcp-socket"],"latest_commit_sha":null,"homepage":"","language":"Java","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/TheRolfFR.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}},"created_at":"2019-11-30T11:33:58.000Z","updated_at":"2024-11-27T11:41:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"86cdac5d-bd74-4c1c-9fc0-0362806fb655","html_url":"https://github.com/TheRolfFR/miniServer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRolfFR%2FminiServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRolfFR%2FminiServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRolfFR%2FminiServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheRolfFR%2FminiServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheRolfFR","download_url":"https://codeload.github.com/TheRolfFR/miniServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245061373,"owners_count":20554563,"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":["beginner-friendly","java","multiplayer","multithreaded-server","multithreading","tcp","tcp-client","tcp-server","tcp-socket"],"created_at":"2024-10-14T10:16:33.149Z","updated_at":"2025-03-23T06:14:31.478Z","avatar_url":"https://github.com/TheRolfFR.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# miniServer\nSimplified Java TCP server. Can be used for multiplayer purposes in games\n\n## Setup guide\nYou can copy folders and files from the ``src`` folder directory directly inside your project.\nIf you don't want the examples, you can delete the ``example`` subfolder.\n\n## How to use it\n\nFirst of all don't forget to import it\n```java\nimport com.therolf.miniServer.Client;\nimport com.therolf.miniServer.Message;\nimport com.therolf.miniServer.Server;\n```\n\n## Client side\n\u003col\u003e\n\u003cli\u003e\nYou need to connect to your server so what you do is that you create a client:\u003cbr\u003e\n\n```java\nString ip = \"127.0.0.1\"; // match with server\nint port = 3000; // match with server\nClient client = new Client(ip, port);\n```\n\u003c/li\u003e\n\u003cli\u003e\nWhat you need next is a username to be recognized ans send messages to everyone :\n\n```java\nString login = \"John Wick\";\nclient.send(login);\n```\n\u003c/li\u003e\n\u003cli\u003eThen when you are authed, the \u003ccode\u003eisAuthed()\u003c/code\u003e method will return true.\u003c/li\u003e\n\u003cli\u003eYou can then finally send strings with the \u003ccode\u003esend(String s)\u003c/code\u003e method.\u003c/li\u003e\n\u003cli\u003eAlternatively, you can listen to incoming messages with the \u003ccode\u003eisReady\u003c/code\u003e and \u003ccode\u003eread\u003c/code\u003e messages:\n\n```java\n// receive messages\nwhile(client.isRunning()) {\n    if(client.isReady()) {\n        Message m = client.read();\n        System.out.println(m.getPseudo() + \": \" + m.getMessage());\n    }\n}\n```\n\u003c/li\u003e\n\u003c/ol\u003e\n\n(Don't forget to wrap it with try catch for error handling)\u003cbr\u003e\nGo checkout [ClientExample.java](./src/example/ClientExample.java) for a real example.\n\n## Server side\n\nThe server side is also simple!\n\u003col\u003e\n\u003cli\u003e\nYou create a server object:\n\n```java\nString port = 3000; // match with client\nString serverName = \"ServerExample\";\nString ip = \"127.0.0.1\"; // match with server\nServer miniServer = new Server(port);\nServer miniServer = new Server(port, serverName);\nServer miniServer = new Server(port, serverName, ip);\n```\n\u003c/li\u003e\n\u003cli\u003e\nYou listen for messages and respond to them if you want:\n\n```java\nminiServer.setMessageListener((fromPseudo, message) -\u003e {\n    switch (message) {\n        case \"hello\":\n            miniServer.sendToEveryoneElse(fromPseudo, fromPseudo + \" says hello\");\n            break;\n        case \"list\":\n            miniServer.sendFromTo(miniServer.getServerName(), fromPseudo, miniServer.getAllPseudos());\n            break;\n        case \"ping\":\n            miniServer.sendFromTo(miniServer.getServerName(), fromPseudo, \"pong\");\n            break;\n        default:\n            miniServer.sendToEveryone(fromPseudo, message);\n            break;\n    }\n});\n```\n\u003c/li\u003e\n\u003cli\u003e\nYou run it and it does its life on its own:\n\n```java\nminiServer.run();\n```\n\u003c/li\u003e\n\nGo checkout [ServerExample.java](./src/example/ServerExample.java) for a real example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftherolffr%2Fminiserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftherolffr%2Fminiserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftherolffr%2Fminiserver/lists"}