|
1 | 1 | Java WebSockets |
2 | 2 | =============== |
3 | | -### CAUTION/TODO: This WebSocket implementation adheres to an older draft of the WebSocket specification (draft 75). The [current draft](http://www.whatwg.org/specs/web-socket-protocol/) (draft 76) is a TODO item/fork-worthy! ### |
4 | 3 |
|
5 | | -This repository contains a simple WebSocket server and client implementation |
6 | | -in Java. The underlying classes use the Java classes `ServerSocketChannel` and |
7 | | -`SocketChannel`, to allow for a non-blocking event-driven model (similar to the |
| 4 | +This repository contains a barebones WebSocket server and client implementation |
| 5 | +written 100% in in Java. The implementation supports both the older draft 75, |
| 6 | +and current draft 76. The underlying classes use the Java |
| 7 | +`ServerSocketChannel` and `SocketChannel` classes, which allows for a |
| 8 | +non-blocking event-driven model (similar to the |
8 | 9 | [WebSocket API](<http://dev.w3.org/html5/websockets/>) for web browsers). |
9 | 10 |
|
10 | 11 | Running the Example |
11 | 12 | ------------------- |
12 | 13 |
|
13 | 14 | There's a simple chat server and client example located in the `example` |
14 | | -folder. |
| 15 | +folder. First, compile the example classes and JAR file: |
| 16 | + ant |
15 | 17 |
|
16 | | -First, start the chat server (a WebSocketServer subclass): |
17 | | - cd example/ |
18 | | - java ChatServer |
| 18 | +Then, start the chat server (a WebSocketServer subclass): |
| 19 | + java -cp example:dist/WebSocket.jar ChatServer |
19 | 20 |
|
20 | 21 | Now that the server is started, we need to connect some clients. Run the |
21 | 22 | Java chat client (a WebSocketClient subclass): |
22 | | - java ChatClient |
| 23 | + java -cp example:dist/WebSocket.jar ChatClient |
23 | 24 |
|
24 | 25 | The chat client is a simple Swing GUI that allows you to send messages to |
25 | | -all other connected clients, and recieve messages from others in a text box. |
| 26 | +all other connected clients, and receive messages from others in a text box. |
26 | 27 |
|
27 | 28 | There's also a simple HTML file chat client `chat.html`, which can be opened |
28 | | -by any browser. If the browser natively supports the WebSocket API, then it will |
29 | | -be used, otherwise it will fall back to a |
| 29 | +by any browser. If the browser natively supports the WebSocket API, then it's |
| 30 | +implementation will be used, otherwise it will fall back to a |
30 | 31 | [Flash-based WebSocket Implementation](<http://github.com/gimite/web-socket-js>). |
31 | 32 |
|
32 | 33 | Writing your own WebSocket Server |
33 | 34 | --------------------------------- |
34 | 35 |
|
| 36 | +The `net.tootallnate.websocket.WebSocketServer` class implements the |
| 37 | +server-side of the |
| 38 | +[WebSocket Protocol](<http://www.whatwg.org/specs/web-socket-protocol/>). |
35 | 39 | A WebSocket server by itself doesn't do anything except establish socket |
36 | | -connections though HTTP. After that it's up to a subclass to add purpose. |
37 | | -The `WebSocketServer` class implements the server-side of the |
38 | | -[WebSocket Protocol](<http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol>). |
| 40 | +connections though HTTP. After that it's up to **your** subclass to add purpose. |
39 | 41 |
|
40 | 42 | Writing your own WebSocket Client |
41 | 43 | --------------------------------- |
42 | 44 |
|
43 | | -The `WebSocketClient` class can connect to valid WebSocket servers. |
44 | | -The constructor expects a valid `ws://` URI to connect to. Important |
45 | | -events `onOpen`, `onClose`, and `onMessage` get fired throughout the life |
46 | | -of the WebSocketClient, and must be implemented in your subclass. |
| 45 | +The `net.tootallnate.websocket.WebSocketClient` class can connect to valid |
| 46 | +WebSocket servers. The constructor expects a valid `ws://` URI to connect to. |
| 47 | +Important events `onOpen`, `onClose`, and `onMessage` get fired throughout the |
| 48 | +life of the WebSocketClient, and must be implemented in your subclass. |
47 | 49 |
|
48 | 50 | License |
49 | 51 | ------- |
|
0 commit comments