Maintained fork of MrStahlfelge/gdx-websockets, which itself forked czyzby's websockets.
This fork preserves SimonIT's TeaVM implementation, keeps the existing API shape for libGDX projects, and serves as the home for ongoing compatibility updates.
Default libGDX Net API provides only TCP sockets and HTTP requests. This library aims to add client-side web sockets support.
It works on all platforms targeted by libGDX.
- Publish JitPack artifacts from
deedywu/gdx-websockets - Keep TeaVM support available and maintained
- Stay close to the original API so existing libGDX projects can migrate with minimal changes
libraries/core: shared websocket API and default serializerslibraries/backends/*: platform-specific websocket implementationslibraries/extensions/*: optional add-ons such as manual serializationexamples/*: runnable sample projects
If you do not already have it, add JitPack to the repositories in your root build.gradle file:
maven { url "https://jitpack.io" }
Use com.github.deedywu.gdx-websockets as the dependency group and the module name as the artifact ID.
Gradle dependency (for libGDX core project):
implementation "com.github.deedywu.gdx-websockets:core:$wsVersion"
GWT module:
<inherits name='com.github.czyzby.websocket.GdxWebSocket' />
Desktop/Android/iOS:
implementation "com.github.deedywu.gdx-websockets:common:$wsVersion"
(based on nv-websocket-client)
Gradle dependency for libGDX html project
implementation "com.github.deedywu.gdx-websockets:core:$wsVersion:sources"
implementation "com.github.deedywu.gdx-websockets:html:$wsVersion"
implementation "com.github.deedywu.gdx-websockets:html:$wsVersion:sources"
GWT module (GdxDefinition.gwt.xml):
<inherits name='com.github.czyzby.websocket.GdxWebSocketGwt' />
This module is based on the TeaVM work originally contributed by SimonIT.
Gradle dependency for libGDX TeaVM web project
implementation "com.github.deedywu.gdx-websockets:teavm-web:$wsVersion"
Use this module with gdx-teavm desktop-c targets. It publishes Java classes plus external_cpp resources that gdx-teavm compiles into the final native executable. It does not bundle a prebuilt native binary.
Gradle dependency for a gdx-teavm desktop-c project
implementation "com.github.deedywu.gdx-websockets:teavm-desktop-c:$wsVersion"
Use this module with gdx-teavm Android targets. It publishes the TeaVM-side websocket factory, the JNI/C bridge resources used by the gdx-teavm Android backend, and the Android runtime helper class that talks to nv-websocket-client.
For a gdx-teavm Android application module:
dependencies {
implementation "com.github.deedywu.gdx-websockets:teavm-android:$wsVersion"
teavm "com.github.deedywu.gdx-websockets:teavm-android:$wsVersion"
}Use this module with experimental gdx-teavm iOS targets. It publishes the TeaVM-side websocket factory plus Objective-C/C bridge resources compiled into the generated Xcode project.
For a gdx-teavm iOS application module:
dependencies {
implementation "com.github.deedywu.gdx-websockets:teavm-ios:$wsVersion"
}Specify the wsVersion in the gradle.properties file in the root directory. Use a tag, branch snapshot, or commit published from this fork:
wsVersion=2.0.7
wsVersion=master-SNAPSHOT
TeaVM web artifact names changed in 2.0.2:
2.0.1usescom.github.deedywu.gdx-websockets:teavm:$wsVersion2.0.2and newer usecom.github.deedywu.gdx-websockets:teavm-web:$wsVersion
Set websocket subprotocols before connect() when a server expects a Sec-WebSocket-Protocol handshake value:
void connectSocket() {
WebSockets.newSocket("wss://example.com/socket")
.withProtocols("graphql-transport-ws", "graphql-ws")
.withPerMessageDeflate(true)
.connect();
}- gdx-websocket-serialization: a custom serialization mechanism, not based on reflection. Alternative to JSON-based communication. More verbose, but gives you full control over the serialization process. Useful for performance-critical applications.
Samples now live under examples.
:examples:desktop: LWJGL3 launcher usingcommon:examples:teavm-desktop-c: TeaVM C / GLFW launcher usingteavm-desktop-c:examples:teavm-web: TeaVM web launcher usingteavm-web:examples:gwt: GWT launcher usinghtml:examples:android: standard Android launcher usingcommonwhen Android SDK is configured:examples:ios: standard RoboVM MetalANGLE iOS launcher usingcommonwhen running on macOS:examples:teavm-android: TeaVM Android launcher usingteavm-androidwhen Android SDK is configured:examples:teavm-ios: TeaVM iOS launcher usingteavm-ioswhen running on macOS
Run it with:
./gradlew :examples:desktop:runFor the iOS example, first list simulators installed on your local machine, then use a simulator name and runtime version from that output:
./gradlew :examples:ios:iosListSimulators
./gradlew :examples:ios:iosRunSimulator \
-PiosSimulatorName="iPhone 15 Pro" \
-PiosSimulatorSdk=17.5For a connected iOS device, list devices and run with signing enabled:
./gradlew :examples:ios:iosListDevices
./gradlew :examples:ios:iosRunDevice -PiosSkipSigning=falseFor the TeaVM iOS example, generate the native payload and run the generated Xcode project on a simulator:
./gradlew :examples:teavm-ios:iosGenerate
./gradlew :examples:teavm-ios:iosInitXcode
./gradlew :examples:teavm-ios:iosRunSimulatorFor a connected TeaVM iOS device build, list devices and run with signing enabled:
./gradlew :examples:teavm-ios:iosListDevices
./gradlew :examples:teavm-ios:iosRunDevice \
-PiosDeviceUdid=<device-udid> \
-PiosSkipSigning=falsePackage the generated TeaVM iOS app as an IPA:
./gradlew :examples:teavm-ios:iosPackageIpaThe demo uses the interactive gdx-teavm websocket UI flow and connects to wss://ws.postman-echo.com/raw by default.
The desktop, Android, RoboVM iOS, TeaVM Android, TeaVM iOS, and TeaVM desktop-c examples also include a local wss://
permessage-deflate option for testing the Netty demo server with a generated self-signed certificate.
Make sure to call CommonWebSockets.initiate() in DesktopLauncher/AndroidLauncher/IOSLauncher launchers before creating web sockets:
// Initiating web sockets module - safe to call before creating application:
CommonWebSockets.initiate();
new LwjglApplication(new MyApplicationListener());
In HTMLLauncher, make sure to call GwtWebSockets.initiate() before creating web sockets:
@Override
public ApplicationListener createApplicationListener() {
// Initiating web sockets module - safe to call before creating application listener:
GwtWebSockets.initiate();
return new MyApplicationListener();
}
In TeaVM web launchers, make sure to call TeaWebSockets.initiate() before creating web sockets:
public static void main (String[] args) {
// Initiating web sockets module - safe to call before creating application:
TeaWebSockets.initiate();
WebApplicationConfiguration config = new WebApplicationConfiguration("canvas");
new WebApplication(new MyApplicationListener(), config);
}
In TeaVM GLFW launchers, make sure to call GLFWWebSockets.initiate() before creating web sockets:
public static void main (String[] args) {
// Initiating web sockets module - safe to call before creating application:
GLFWWebSockets.initiate();
new GLFWApplication(new MyApplicationListener(), config);
}
In TeaVM Android launchers, make sure to call AndroidWebSockets.initiate() before creating web sockets:
public static void main (String[] args) {
// Initiating web sockets module - safe to call before creating application:
AndroidWebSockets.initiate();
new AndroidApplication(new MyApplicationListener(), config);
}
In TeaVM iOS launchers, make sure to call IOSWebSockets.initiate() before creating web sockets:
public static void main (String[] args) {
// Initiating web sockets module - safe to call before creating application:
IOSWebSockets.initiate();
new IOSApplication(new MyApplicationListener(), config);
}
WebSocket socket = WebSockets.newSocket(WebSockets.toWebSocketUrl(address, port));
socket.setSendGracefully(true);
socket.setPerMessageDeflate(true); // Optional. Set before connect() to request permessage-deflate.
socket.addListener(new WebSocketListener() { ... });
socket.connect();
setPerMessageDeflate(true) is a core API flag. Backends that can control websocket extension negotiation request
permessage-deflate during the handshake; other backends may ignore the flag.
For local development only, WebSockets.newInsecureSocket(url) requests a socket that trusts every TLS certificate and
disables hostname verification. This is useful for local wss:// testing with a self-signed certificate, local IP
address, or temporary hostname mismatch:
WebSocket socket = WebSockets.newInsecureSocket("wss://192.168.2.1:8080/");
Do not use this helper for production traffic. Backends that cannot override TLS validation, such as browser-backed
websocket implementations, reject this helper with a WebSocketException. The common JVM backend, TeaVM Android
backend, TeaVM iOS backend, and TeaVM desktop-c backend support it.
For GWT/html and TeaVM web examples, the browser's own TLS validation still applies: use ws:// for local testing, or
install and trust a local certificate that matches the wss:// host before using the local WSS option.
- Added websocket subprotocol support and fluent
WebSocket.with...configuration helpers. - Updated available
gdx-teavmintegrations to1.6.0, TeaVM0.15.0, and Java 17 for TeaVM modules. - Improved local WSS/permessage-deflate examples and documentation across desktop, browser, Android, iOS, and TeaVM targets.
- Marked insecure local WSS helpers as deprecated while keeping them available for explicit development-only testing.
- Fixed local demo build and IDE rough edges, including BouncyCastle certificate generation and the GWT source set declaration.
- Added local-development WSS testing with
WebSockets.newInsecureSocket(url)on common JVM, TeaVM Android, TeaVM iOS, and TeaVM desktop-c. - Added
NvWebSocket.setSSLContext(...)for custom JVM TLS trust setup. - Added local WSS demo options and self-signed certificate generation in the example server.
- Made browser-backed GWT/html and TeaVM web report clear errors for unsupported insecure WSS testing.
- Fixed stale demo status after reconnecting.
- Added core API support for requesting
permessage-deflatebefore connecting, with backend support where websocket extension negotiation is exposed. - Unified the websocket examples across desktop, GWT, Android, iOS, and TeaVM targets with a shared demo selector, consistent launcher behavior, and matching mobile UI scaling.
- Added a local Netty
permessage-deflatetest server plus example flows for local websocket testing and extension negotiation reporting where supported.
- Added TeaVM Android support for
gdx-teavmAndroid targets, including theAndroidWebSocketsfactory, JNI/C bridge resources, and an Android runtime bridge backed bynv-websocket-client. - Added TeaVM iOS support for experimental
gdx-teavmiOS targets, including theIOSWebSocketsfactory and Objective-C/C bridge resources backed byNSURLSessionWebSocketTask. - Updated the root README with Android and iOS TeaVM dependencies and launcher initialization examples.
- Added the TeaVM Desktop C / GLFW backend for
gdx-teavmdesktop-c targets. - Renamed the TeaVM web artifact from
teavmtoteavm-web; usecom.github.deedywu.gdx-websockets:teavm-web:$wsVersionfrom this release onward. - Published
external_cppresources and helper scripts for linking websocket support into generated native desktop-c executables.
- Prepared the fork for JitPack releases that work for JDK 17 consumers.
- Centralized Java release configuration in the root Gradle build: Java 8 for regular modules and Java 11 for TeaVM modules.
- Initial release as
2.0.1.
- Versions before
2.0.1are equivalent to MrStahlfelge/gdx-websockets1.9.10.3.