Java-WebSocket

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


Project maintained by marci4 Hosted on GitHub Pages — Theme by mattgraham

Java WebSockets

This repository contains a barebones WebSocket server and client implementation written in 100% Java. The underlying classes are implemented java.nio, which allows for a non-blocking event-driven model (similar to the WebSocket API for web browsers).

Implemented WebSocket protocol versions are:

Here some more details about protocol versions/drafts.

Getting started

Dependency management tools

You can find instructions on how to use this library for your dependency management tool in mvnrepository.com.

Github releases

You can also find any releases here.

Writing your own WebSocket Server

The org.java_websocket.server.WebSocketServer abstract class implements the server-side of the WebSocket 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

The org.java_websocket.client.WebSocketClient abstract class can connect to valid WebSocket servers. The constructor expects a valid ws:// or wss:// URI to connect to. Important events onOpen, onClose, onMessage and onError 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.

Examples

You can find a lot of additional examples here.

License

Everything found in this repo is licensed under an MIT license. See the LICENSE file for specifics.