1515import java .util .Set ;
1616import java .util .concurrent .LinkedBlockingQueue ;
1717
18- import net .tootallnate .websocket .WebSocketListener .Draft ;
19-
2018/**
2119 * The <tt>WebSocketClient</tt> is an abstract class that expects a valid
2220 * "ws://" URI to connect to. When connected, an instance recieves important
@@ -51,9 +49,9 @@ public abstract class WebSocketClient implements Runnable, WebSocketListener {
5149 */
5250 private boolean running ;
5351 /**
54- * The Websocket mode this client is in .
52+ * The Draft of the WebSocket protocol the Client is adhering to .
5553 */
56- private Draft draft ;
54+ private WebSocketDraft draft ;
5755 /**
5856 * Number 1 used in handshake
5957 */
@@ -67,14 +65,18 @@ public abstract class WebSocketClient implements Runnable, WebSocketListener {
6765 */
6866 private byte [] key3 = null ;
6967
70- // CONSTRUCTOR /////////////////////////////////////////////////////////////
68+ // CONSTRUCTORS ////////////////////////////////////////////////////////////
69+ public WebSocketClient (URI serverURI ) {
70+ this (serverURI , WebSocketDraft .AUTO );
71+ }
72+
7173 /**
7274 * Constructs a WebSocketClient instance and sets it to the connect to the
7375 * specified URI. The client does not attampt to connect automatically. You
7476 * must call <var>connect</var> first to initiate the socket connection.
7577 * @param serverUri The <tt>URI</tt> of the WebSocket server to connect to.
7678 */
77- public WebSocketClient (URI serverUri ,Draft draft ) {
79+ public WebSocketClient (URI serverUri , WebSocketDraft draft ) {
7880 this .uri = serverUri ;
7981 this .draft = draft ;
8082 }
@@ -89,7 +91,7 @@ public URI getURI() {
8991 }
9092
9193 @ Override
92- public Draft getDraft () {
94+ public WebSocketDraft getDraft () {
9395 return this .draft ;
9496 }
9597
@@ -179,7 +181,7 @@ public void run() {
179181 "Connection: Upgrade\r \n " +
180182 "Host: " + host + "\r \n " +
181183 "Origin: " + origin + "\r \n " ;
182- if (this .draft == Draft .DRAFT76 ) {
184+ if (this .draft == WebSocketDraft .DRAFT76 ) {
183185 request += "Sec-WebSocket-Key1: " + this .generateKey () + "\r \n " ;
184186 request += "Sec-WebSocket-Key2: " + this .generateKey () + "\r \n " ;
185187 this .key3 = new byte [8 ];
@@ -257,31 +259,31 @@ private String generateKey() {
257259 public boolean onHandshakeRecieved (WebSocket conn , String handshake , byte [] reply ) throws IOException , NoSuchAlgorithmException {
258260 // TODO: Do some parsing of the returned handshake, and close connection
259261 // (return false) if we recieved anything unexpected.
260- if (this .draft == Draft .DRAFT76 ) {
262+ if (this .draft == WebSocketDraft .DRAFT76 ) {
261263 if (reply == null ) {
262264 return false ;
263265 }
264266 byte [] challenge = new byte [] {
265- (byte )( this .number1 >> 24 ),
266- (byte )( (this .number1 << 8 ) >> 24 ),
267- (byte )( (this .number1 << 16 ) >> 24 ),
268- (byte )( (this .number1 << 24 ) >> 24 ),
269- (byte )( this .number2 >> 24 ),
270- (byte )( (this .number2 << 8 ) >> 24 ),
271- (byte )( (this .number2 << 16 ) >> 24 ),
272- (byte )( (this .number2 << 24 ) >> 24 ),
273- this .key3 [0 ],
274- this .key3 [1 ],
275- this .key3 [2 ],
276- this .key3 [3 ],
277- this .key3 [4 ],
278- this .key3 [5 ],
279- this .key3 [6 ],
280- this .key3 [7 ]
267+ (byte )( this .number1 >> 24 ),
268+ (byte )( (this .number1 << 8 ) >> 24 ),
269+ (byte )( (this .number1 << 16 ) >> 24 ),
270+ (byte )( (this .number1 << 24 ) >> 24 ),
271+ (byte )( this .number2 >> 24 ),
272+ (byte )( (this .number2 << 8 ) >> 24 ),
273+ (byte )( (this .number2 << 16 ) >> 24 ),
274+ (byte )( (this .number2 << 24 ) >> 24 ),
275+ this .key3 [0 ],
276+ this .key3 [1 ],
277+ this .key3 [2 ],
278+ this .key3 [3 ],
279+ this .key3 [4 ],
280+ this .key3 [5 ],
281+ this .key3 [6 ],
282+ this .key3 [7 ]
281283 };
282284 MessageDigest md5 = MessageDigest .getInstance ("MD5" );
283285 byte [] expected = md5 .digest (challenge );
284- for (int i = 0 ; i < reply .length ; i ++){
286+ for (int i = 0 ; i < reply .length ; i ++) {
285287 if (expected [i ] != reply [i ]) {
286288 return false ;
287289 }
0 commit comments