Skip to content

Commit cd957da

Browse files
committed
2 parents 53395cc + a9f8707 commit cd957da

File tree

7 files changed

+2078
-15
lines changed

7 files changed

+2078
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
*.class
22
*.svn
3-
3+
*~

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010 Nathan Rajlich
1+
Copyright (c) 2010-2012 Nathan Rajlich
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

README.markdown

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
Java WebSockets
22
===============
33

4-
### Note: This lib currently only supports the older draft 75 and draft 76.
5-
### Pull requests for the latests drafts would be more than accepted!
6-
74
This repository contains a barebones WebSocket server and client implementation
85
written in 100% Java. The underlying classes are implemented using the Java
96
`ServerSocketChannel` and `SocketChannel` classes, which allows for a
107
non-blocking event-driven model (similar to the
118
[WebSocket API](http://dev.w3.org/html5/websockets/) for web browsers).
129

10+
Implemented WebSocket protocol versions are:
11+
12+
* [Hixie 75](http://tools.ietf.org/id/draft-hixie-thewebsocketprotocol-75.txt)
13+
* [Hixie 76](http://tools.ietf.org/id/draft-hixie-thewebsocketprotocol-76.txt)
14+
* [Hybi 10](http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-10.txt)
15+
* [Hybi 17](http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-17.txt)
16+
1317
Running the Example
1418
-------------------
1519

dist/WebSocket.jar

30.4 KB
Binary file not shown.

src/net/tootallnate/websocket/Base64.java

Lines changed: 2065 additions & 0 deletions
Large diffs are not rendered by default.

src/net/tootallnate/websocket/WebSocket.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,8 @@ public enum Role{
6060
* The byte representing the end of a WebSocket text frame.
6161
*/
6262
public static final byte END_OF_FRAME = (byte)0xFF;
63-
63+
6464
public static final boolean DEBUG = false;
65-
66-
static{
67-
if ( DEBUG ) {
68-
System.out.println("WebSocket debug mode enabled");
69-
}
70-
}
7165

7266

7367
// INSTANCE PROPERTIES /////////////////////////////////////////////////////

src/net/tootallnate/websocket/drafts/Draft_10.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Random;
1010

11+
import net.tootallnate.websocket.Base64;
1112
import net.tootallnate.websocket.Draft;
1213
import net.tootallnate.websocket.FrameBuilder;
1314
import net.tootallnate.websocket.Framedata;
@@ -16,7 +17,6 @@
1617
import net.tootallnate.websocket.HandshakeBuilder;
1718
import net.tootallnate.websocket.Handshakedata;
1819
import net.tootallnate.websocket.exeptions.InvalidHandshakeException;
19-
import sun.misc.BASE64Encoder;
2020

2121

2222
public class Draft_10 extends Draft {
@@ -158,7 +158,7 @@ private String generateFinalKey( String in ){
158158
} catch ( NoSuchAlgorithmException e ) {
159159
throw new RuntimeException ( e );
160160
}
161-
return new BASE64Encoder ().encode ( sh1.digest ( acc.getBytes () ) );
161+
return Base64.encodeBytes ( sh1.digest ( acc.getBytes () ) );
162162
}
163163

164164
@Override
@@ -169,7 +169,7 @@ public HandshakeBuilder postProcessHandshakeRequestAsClient( HandshakeBuilder re
169169

170170
byte[] random = new byte[16];
171171
new Random().nextBytes( random );
172-
request.put( "Sec-WebSocket-Key" , new BASE64Encoder().encode ( random ) );
172+
request.put( "Sec-WebSocket-Key" , Base64.encodeBytes( random ) );
173173

174174
return request;
175175
}

0 commit comments

Comments
 (0)