Github url


by TooTallNate

TooTallNate /Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.

7.0K Stars 2.0K Forks Last release: 2 months ago (v1.5.1) MIT License 1.0K Commits 26 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Java WebSockets

Build StatusJavadocsMaven CentralSonatype Nexus (Snapshots)

This repository contains a barebones WebSocket server and client implementation written in 100% Java. The underlying classes are implemented


, which allows for a non-blocking event-driven model (similar to theWebSocket API for web browsers).

Implemented WebSocket protocol versions are:

Here some more details about protocol versions/drafts.

Getting Started

Dependency management tools

Below is a brief guide to using dependency management tools like maven or gradle.


To use maven add this dependency to your pom.xml:



To use Gradle add the maven central repository to your repositories list:

xml mavenCentral()

Then you can just add the latest version to your build.

xml compile ""


This library uses SLF4J for logging and does not ship with any default logging implementation.

Exceptions are using the log level


and debug logging will be done with log level



Feel free to use whichever logging framework you desire and use the corresponding binding in your dependency management.

If you want to get started, take a look at the SimpleLogger example.

Standalone jar

If you do not use any dependency management tool, you can find the latest standalone jar here.

Writing your own WebSocket Server


abstract class implements the server-side of theWebSocket Protocol. A WebSocket server by itself doesn't do anything except establish socket connections though HTTP. After that it's up to your subclass to add purpose.

An example for a WebSocketServer can be found in both the wiki and the example folder.

Writing your own WebSocket Client


abstract class can connect to valid WebSocket servers. The constructor expects a valid


URI to connect to. Important events








get fired throughout the life of the WebSocketClient, and must be implemented in your subclass.

An example for a WebSocketClient can be found in both the wiki and the example folder.


You can find a lot of examples here.

WSS Support

This library supports wss. To see how to use wss please take a look at the examples.

If you do not have a valid certificate in place then you will have to create a self signed one. Browsers will simply refuse the connection in case of a bad certificate and will not ask the user to accept it. So the first step will be to make a browser to accept your self signed certificate. (\_bug.cgi?id=594502 ).
If the websocket server url is


visit the url


with your browser. The browser will recognize the handshake and allow you to accept the certificate. This technique is also demonstrated in this video.

The vm option

can help to find out if there is a problem with the certificate.

It is currently not possible to accept ws and wss connections at the same time via the same websocket server instance.

For some reason Firefox does not allow multiple connections to the same wss server if the server uses a different port than the default port (443).

If you want to use


on the android platfrom you should take a look at this.

I ( @Davidiusdadi ) would be glad if you would give some feedback whether wss is working fine for you or not.

Minimum Required JDK


is known to work with:

  • Java 1.7 and higher

Other JRE implementations may work as well, but haven't been tested.


Everything found in this repo is licensed under an MIT license. See the


file for specifics.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.