{"id":17691209,"url":"https://github.com/mrstahlfelge/gdx-websockets","last_synced_at":"2025-06-10T19:05:23.572Z","repository":{"id":50193231,"uuid":"313751202","full_name":"MrStahlfelge/gdx-websockets","owner":"MrStahlfelge","description":"libGDX websockets implementation","archived":false,"fork":false,"pushed_at":"2024-10-16T15:25:34.000Z","size":158,"stargazers_count":30,"open_issues_count":11,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T05:07:17.753Z","etag":null,"topics":["libgdx","multiplayer","websockets"],"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/MrStahlfelge.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":"2020-11-17T21:47:56.000Z","updated_at":"2025-03-06T07:53:07.000Z","dependencies_parsed_at":"2024-10-24T14:32:46.047Z","dependency_job_id":"1491836a-0865-4cc8-ba0f-624a5ea5f8d8","html_url":"https://github.com/MrStahlfelge/gdx-websockets","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrStahlfelge%2Fgdx-websockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrStahlfelge%2Fgdx-websockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrStahlfelge%2Fgdx-websockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrStahlfelge%2Fgdx-websockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrStahlfelge","download_url":"https://codeload.github.com/MrStahlfelge/gdx-websockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248914888,"owners_count":21182528,"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":["libgdx","multiplayer","websockets"],"created_at":"2024-10-24T12:07:54.414Z","updated_at":"2025-04-14T16:24:03.235Z","avatar_url":"https://github.com/MrStahlfelge.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libGDX Web Sockets\n\nFork of [czyzby's websockets](https://github.com/czyzby/gdx-lml/tree/master/websocket), which seem to be unmaintained.\n\nSee there for examples.\n\nDefault libGDX `Net` API provides only TCP sockets and HTTP requests. This library aims to add client-side web sockets support.\nIt works on all platforms targeted by libGDX.\n\n## Dependencies\nIf you don't have already, add Jitpack to your repositories in root `build.gradle` file:\n\n        maven { url \"https://jitpack.io\" }\n\n`Gradle` dependency (for libGDX core project):\n```\n         implementation \"com.github.MrStahlfelge.gdx-websockets:core:$wsVersion\"\n```\n\nGWT module:\n```\n         \u003cinherits name='com.github.czyzby.websocket.GdxWebSocket' /\u003e\n```\n\nDesktop/Android/iOS:\n```\n         implementation \"com.github.MrStahlfelge.gdx-websockets:common:$wsVersion\"\n```\n\n(based on [nv-websocket-client](https://github.com/TakahikoKawasaki/nv-websocket-client))\n\n### GWT (Web)\n`Gradle` dependency for libGDX html project\n```\n        implementation \"com.github.MrStahlfelge.gdx-websockets:core:$wsVersion:sources\"\n        implementation \"com.github.MrStahlfelge.gdx-websockets:html:$wsVersion\"\n        implementation \"com.github.MrStahlfelge.gdx-websockets:html:$wsVersion:sources\"\n```\n\nGWT module (GdxDefinition.gwt.xml):\n```\n        \u003cinherits name='com.github.czyzby.websocket.GdxWebSocketGwt' /\u003e\n```\n\n### Version\n\nSpecify the `wsVersion` in the `gradle.properties` file in the root directory:\n\n`wsVersion=1.9.10.3` (or the latest version)\n\n### Extensions\n\n- [gdx-websocket-serialization](https://github.com/MrStahlfelge/gdx-websockets/tree/master/serialization): a custom serialization mechanism, not based on reflection. Alternative to JSON-based communication. More verbose, but gives you full control over (de)serialization process. Useful for performance-critical applications.\n\n## Basic usage\n\n### Initialization\n\nMake sure to call `CommonWebSockets.initiate()` in DesktopLauncher/AndroidLauncher/IOSLauncher launchers before creating web sockets:\n```\n        // Initiating web sockets module - safe to call before creating application:\n        CommonWebSockets.initiate();\n        new LwjglApplication(new MyApplicationListener());\n```\n\nIn HTMLLauncher, make sure to call `GwtWebSockets.initiate()` before creating web sockets:\n```\n        @Override\n        public ApplicationListener createApplicationListener() {\n            // Initiating web sockets module - safe to call before creating application listener:\n            GwtWebSockets.initiate();\n            return new MyApplicationListener();\n        }\n```\n\n### Connecting to a server\n\n```\n        WebSocket socket = WebSockets.newSocket(WebSockets.toWebSocketUrl(address, port));\n        socket.setSendGracefully(true);\n        socket.addListener(new WebsocketListener() { ... });\n        socket.connect();\n```\n\n## Changes\n\n1.5 -\u003e 1.6\n\n- Added `AbstractWebSocketListener`, which handles object deserialization and logs errors. This is a solid base for your `WebSocketListener` implementation if don't use pure string-based communication. \n- Added `WebSocketHandler`, which extends `AbstractWebSocketListener` even further. Instead of dealing with raw `Object` types and having to determine packet type on your own, you can register a `Handler` to a specific packet class and it will be invoked each time a packet of the selected type is received.\n- Added default `Serializer` implementation: `JsonSerializer`. Uses **LibGDX** `Json` API to serialize objects as strings.\n- Added `WebSockets#DEFAULT_SERIALIZER`. Modify this field to automatically assign serializer of your choice to all new web socket instances.\n- Added `Base64Serializer`. Uses **LibGDX** `Base64Coder` API to encode and decode the data to and from *BASE64*. Wraps around an existing serializer.\n- Added custom serialization in [gdx-websocket-serialization](natives/serialization) library. `ManualSerializer` is an alternative to the default `JsonSerializer`.\n- Added `WebSockets#closeGracefully(WebSocket)` null-safe utility method. Attempts to close the passed web socket and catches any thrown exceptions (their message is logged using `Gdx.app.debug` method). If passed web socket is null, it will be ignored. Useful for application disposing methods, when you don't exactly care if the web socket is not properly closed and *have to* continue disposing other native assets, even if `close()` call fails.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrstahlfelge%2Fgdx-websockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrstahlfelge%2Fgdx-websockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrstahlfelge%2Fgdx-websockets/lists"}