gitmyhub

Java-WebSocket

Java ★ 11k updated 5mo ago

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

A pure-Java library for adding WebSocket server or client support to any Java application, with non-blocking connections and no external dependencies beyond an optional logging framework.

JavaMavenGradleSLF4Jsetup: easycomplexity 2/5

Java-WebSocket is a library that lets Java applications send and receive messages over WebSocket connections. WebSocket is a communication protocol that keeps a two-way connection open between a client (like a browser or app) and a server, so either side can send data at any time without the overhead of making a new request each time.

The library is written entirely in Java and uses the java.nio package, which means it handles connections without blocking other work while waiting for data to arrive. This makes it suitable for applications that need to handle many simultaneous connections.

To build a server, you extend the library's WebSocketServer class and implement the event methods you care about. To build a client, you extend WebSocketClient and connect to a ws:// or wss:// address. In both cases the library fires events like onOpen, onClose, onMessage, and onError, and you write the code that responds to each one.

The library supports the two main versions of the WebSocket protocol (RFC 6455 and RFC 7692) and also works with secure WebSocket connections (wss://). Secure connections require a valid certificate; the README includes notes on handling self-signed certificates during development.

Adding the library to a Java project is straightforward via Maven or Gradle. A standalone jar is available for projects that do not use a dependency manager. The library uses SLF4J for logging, which means you choose and supply your own logging framework rather than having one forced on you. Java 8 or higher is required. The project is MIT-licensed.

Where it fits