This repository contains a barebones WebSocket server and client implementation
written in 100% Java. The implementation supports both the older draft 75,
and current draft 76. The underlying classes use the Java
SocketChannel classes, which allows for a
non-blocking event-driven model (similar to the
WebSocket API for web browsers).
Running the Example
There's a simple chat server and client example located in the
folder. First, compile the example classes and JAR file:
Then, start the chat server (a
java -cp example:dist/WebSocket.jar ChatServer
Now that the server is started, we need to connect some clients. Run the
Java chat client (a
java -cp example:dist/WebSocket.jar ChatClient
The chat client is a simple Swing GUI application that allows you to send messages to all other connected clients, and receive messages from others in a text box.
There's also a simple HTML file chat client
chat.html, which can be opened
by any browser. If the browser natively supports the WebSocket API, then it's
implementation will be used, otherwise it will fall back to a
Flash-based WebSocket Implementation.
Writing your own WebSocket Server
net.tootallnate.websocket.WebSocketServer abstract class implements the
server-side of the
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.
Writing your own WebSocket Client
net.tootallnate.websocket.WebSocketClient abstract class can connect to
valid WebSocket servers. The constructor expects a valid
ws:// URI to
connect to. Important events
onMessage get fired
throughout the life of the WebSocketClient, and must be implemented in your
Everything found in this repo is licensed under an MIT license. See
LICENSE file for specifics.