Skip to content

Commit d14c44c

Browse files
committed
Initial commit. This is currently is stable implementation of a
WebSocket server and client. Underlying Java WebSocket code probably won't need to be changed much more. The only commits planned for down the line are better documentation and examples.
0 parents  commit d14c44c

28 files changed

+4614
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.class
2+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2010 Nathan Rajlich
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.markdown

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Java WebSockets
2+
===============
3+
4+
This repository contains a simple WebSocket server and client implementation
5+
in Java. The underlying classes use `ServerSocketChannel` and `SocketChannel`
6+
objects, to allow for a non-blocking event-driven model (similar to the
7+
WebSocket API for web browsers).
8+
9+
Running the Example
10+
-------------------
11+
12+
There's a simple chat server and client example located in the `example`
13+
folder.
14+
15+
First, start the chat server (a WebSocketServer subclass):
16+
cd example/
17+
java ChatServer
18+
19+
Now that the server is started, we need to connect some clients. Run the
20+
Java chat client (a WebSocketClient subclass):
21+
java ChatClient
22+
23+
The chat client is a simple Swing GUI that allows you to send messages to
24+
all other connected clients, and recieve messages from others in a text box.
25+
26+
There's also a simple HTML file chat client `chat.html`, which can be opened
27+
by any browser that supports the WebSocket API (currently Chrome 4, Safari
28+
nightlies, Firefox nightlies).
29+
30+
Writing your own WebSocket Server
31+
---------------------------------
32+
33+
A WebSocketServer by itself doesn't do anything except establish socket
34+
connections though HTTP. After that it's up to a subclass to add purpose.
35+
36+
37+
Writing your own WebSocket Client
38+
---------------------------------
39+
40+
The WebSocketClient aims to simulate the WebSocket API
41+
(<http://dev.w3.org/html5/websockets/>) as closely as possible.
42+
The constructor expects a valid "ws://" URI to connect to. Important
43+
events `onOpen`, `onClose`, and `onMessage` get fired throughout the life
44+
of the WebSocketClient, and must be implemented in your subclass.
45+
46+
License
47+
-------
48+
49+
Everything found in this repo is licensed under an MIT license. See
50+
the `LICENSE` file for specifics.

0 commit comments

Comments
 (0)