Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ee27864
Add gsolo SHA1 algorithm.
May 2, 2011
8b52ec4
com/gsolo/encryption/SHA1.as: stop compile warnings.
May 2, 2011
20c16e6
Fix protocol attribute handling.
May 2, 2011
4084a2c
Implement HyBi-07 version of the protocol.
May 2, 2011
128b3c7
Add HyBi-07 client masking.
May 2, 2011
9e67e24
Use byte length rather than character length.
kanaka May 6, 2011
fd5fa42
Merging.
gimite May 7, 2011
fa9e686
Merge branch 'master' into hybi-07
gimite May 7, 2011
4be643b
Merge remote branch 'gimite/master' into hybi-08
kanaka Aug 29, 2011
a308f86
Merge branch 'master' into hybi-07
gimite Sep 17, 2011
1646609
Style fixes.
gimite Sep 17, 2011
7e12c8a
Switching to hybi-10 protocol.
gimite Sep 17, 2011
a14e6f0
Implementing pong.
gimite Sep 18, 2011
c1e7a1a
Some more refactoring.
gimite Sep 18, 2011
24acbab
Fixing closing handshake.
gimite Sep 18, 2011
77507da
Updating README and adding NEWS.
gimite Sep 18, 2011
b54ae42
Updating NEWS.
gimite Sep 18, 2011
ba3d7af
Fixing a bug that decoded key was not 16 bytes.
gimite Sep 19, 2011
d3f2b90
Sending closing frame for some errors.
gimite Sep 19, 2011
23e7488
Handling IOError on send().
gimite Sep 25, 2011
f056e9f
Using status code to express connection error and server closing.
gimite Sep 25, 2011
55ae639
Adding wasClean, code, reason to onclose event object. Code was parti…
gimite Sep 26, 2011
1402307
Closing connection on masked frame from server. Issue #103
gimite Nov 5, 2011
4f7b9f8
Initializing automatically when web_socket.js is dynamically loaded.
gimite Dec 11, 2011
841b01d
Using swfobject.addDomLoadEvent() to simplify the initialization.
gimite Dec 14, 2011
b16e4ce
Using MozWebSocket when available. Issue #87
gimite Dec 17, 2011
47c316c
Firing close event on error in send(). Hopefully fixes issue #92 .
gimite Dec 17, 2011
30b0e3c
Switching to WebSocket version defined in RFC 6455.
gimite Dec 27, 2011
6ca1919
Updating README.
gimite Jan 30, 2012
2ee87e9
Adding reference to futurechimp's Ruby implementation of Flash socket…
gimite Mar 17, 2012
5c5ae54
@= flag of WebSocket implementation
abonec Aug 9, 2012
7677e7a
Renaming flash_implemented to __isFlashImplementation.
gimite Aug 9, 2012
1eb68ad
Include the patch from http://code.google.com/p/as3crypto/issues/deta…
jamadden Nov 1, 2012
10410eb
Rebuilding SWF files.
gimite Nov 3, 2012
b5f4ab7
Fixing a bug that it required whitespace after colon in the header. #126
gimite Dec 4, 2012
5c313e9
Add swfobject.js v2.2 source for DFSG compatibility.
kanaka Apr 12, 2013
7c4558f
Merge branch 'dfsg' of https://github.com/kanaka/web-socket-js
gimite Apr 25, 2013
c0855c6
Moving swfobject-src.js.
gimite Apr 25, 2013
0991abd
handle continuation frame from server #129
ken107 Jun 24, 2013
15db822
Recompiling SWF files.
gimite Jul 9, 2013
08cd896
Adding LICENCE.txt.
gimite Jul 9, 2013
c1fd4e0
Renaming license file.
gimite Jul 9, 2013
9c755f9
Fix for Issue #142
cope Dec 12, 2013
338760f
Using typeof(MessageEvent) to switch two ways to create MessageEvent.
gimite Dec 15, 2013
4405e7d
Adding bower.json. #148
gimite Jan 16, 2014
87ffc52
fix #151
x25 Mar 12, 2014
f64a2b9
Updating SWF files.
gimite Apr 3, 2014
35778e4
Remove moot `version` property from bower.json
kkirsche Jun 12, 2015
282e4d4
Merge pull request #162 from kkirsche/patch-1
gimite Jun 17, 2015
534dd4b
fix the empty cookie bug
lightsocks Oct 10, 2015
1ab03b3
Merge pull request #169 from lightsocks/master
gimite Oct 24, 2015
3010e94
Suppress SecurityError on processEvents(). #159
gimite Nov 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Using status code to express connection error and server closing.
  • Loading branch information
gimite committed Sep 25, 2011
commit f056e9ff49be11d97b500eafb59f8ed311cb0831
Binary file modified WebSocketMain.swf
Binary file not shown.
Binary file modified WebSocketMainInsecure.zip
Binary file not shown.
49 changes: 26 additions & 23 deletions flash-src/src/net/gimite/websocket/WebSocket.as
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class WebSocket extends EventDispatcher {
private static var OPCODE_PING:int = 0x09;
private static var OPCODE_PONG:int = 0x0a;

private static var STATUS_SERVER_CLOSED:int = 5000;
private static var STATUS_CONNECTION_ERROR:int = 5001;

private var id:int;
private var url:String;
private var scheme:String;
Expand Down Expand Up @@ -140,14 +143,14 @@ public class WebSocket extends EventDispatcher {
}

public function send(encData:String):int {
logger.log("send: " + data);
var data:String;
try {
data = decodeURIComponent(encData);
} catch (ex:URIError) {
logger.error("SYNTAX_ERR: URIError in send()");
return 0;
}
logger.log("send: " + data);
var dataBytes:ByteArray = new ByteArray();
dataBytes.writeUTFBytes(data);
if (readyState == OPEN) {
Expand All @@ -168,34 +171,34 @@ public class WebSocket extends EventDispatcher {
}
}

public function close(code:int = 1000, reason:String = "",
isConnectionError:Boolean = false, byServer:Boolean = false):void {
var isError:Boolean = code != 1000 || isConnectionError;
if (!isConnectionError && code != 1000) {
public function close(code:int = 1000, reason:String = ""):void {
if (code != 1000 && code != STATUS_SERVER_CLOSED && code != STATUS_CONNECTION_ERROR) {
logger.error("Fail connection: code=" + code + ", reason=" + reason);
}
var closeConnection:Boolean = code != 1000;
try {
if (readyState == OPEN && !isConnectionError) {
if (readyState == OPEN && code != STATUS_CONNECTION_ERROR) {
var frame:WebSocketFrame = new WebSocketFrame();
frame.opcode = OPCODE_CLOSE;
frame.payload = new ByteArray();
if (code != 1000 && reason.length > 0) {
frame.payload.writeShort(code);
var sentCode:int = code == STATUS_SERVER_CLOSED ? 1000 : code;
if (sentCode != 1000 || reason.length > 0) {
frame.payload.writeShort(sentCode);
frame.payload.writeUTFBytes(reason);
}
sendFrame(frame);
}
if (byServer || isError) {
if (closeConnection) {
socket.close();
}
} catch (ex:Error) {
logger.error("Error: " + ex.message);
}
if (byServer || isError) {
if (closeConnection) {
logger.log("closed");
readyState = CLOSED;
var eventName:String =
(readyState != CONNECTING && isConnectionError) ? "error" : "close";
(readyState != CONNECTING && code == STATUS_CONNECTION_ERROR) ? "error" : "close";
this.dispatchEvent(new WebSocketEvent(eventName));
} else {
logger.log("closing");
Expand Down Expand Up @@ -257,7 +260,7 @@ public class WebSocket extends EventDispatcher {
"error communicating with Web Socket server at " + url +
" (IoError: " + event.text + ")";
}
onError(message);
onConnectionError(message);
}

private function onSocketSecurityError(event:SecurityErrorEvent):void {
Expand All @@ -271,13 +274,13 @@ public class WebSocket extends EventDispatcher {
"error communicating with Web Socket server at " + url +
" (SecurityError: " + event.text + ")";
}
onError(message);
onConnectionError(message);
}

private function onError(message:String):void {
private function onConnectionError(message:String):void {
if (readyState == CLOSED) return;
logger.error(message);
close(0, "", true);
close(STATUS_CONNECTION_ERROR);
}

private function onSocketData(event:ProgressEvent):void {
Expand Down Expand Up @@ -330,7 +333,7 @@ public class WebSocket extends EventDispatcher {
case OPCODE_CLOSE:
// TODO: extract code and reason string
logger.log("received closing frame");
close(1000, "", false, true);
close(STATUS_SERVER_CLOSED);
break;
case OPCODE_PING:
sendPong(frame.payload);
Expand All @@ -350,7 +353,7 @@ public class WebSocket extends EventDispatcher {
private function validateHandshake(headerStr:String):Boolean {
var lines:Array = headerStr.split(/\r\n/);
if (!lines[0].match(/^HTTP\/1.1 101 /)) {
onError("bad response: " + lines[0]);
onConnectionError("bad response: " + lines[0]);
return false;
}
var header:Object = {};
Expand All @@ -359,22 +362,22 @@ public class WebSocket extends EventDispatcher {
if (lines[i].length == 0) continue;
var m:Array = lines[i].match(/^(\S+): (.*)$/);
if (!m) {
onError("failed to parse response header line: " + lines[i]);
onConnectionError("failed to parse response header line: " + lines[i]);
return false;
}
header[m[1].toLowerCase()] = m[2];
lowerHeader[m[1].toLowerCase()] = m[2].toLowerCase();
}
if (lowerHeader["upgrade"] != "websocket") {
onError("invalid Upgrade: " + header["Upgrade"]);
onConnectionError("invalid Upgrade: " + header["Upgrade"]);
return false;
}
if (lowerHeader["connection"] != "upgrade") {
onError("invalid Connection: " + header["Connection"]);
onConnectionError("invalid Connection: " + header["Connection"]);
return false;
}
if (!lowerHeader["sec-websocket-accept"]) {
onError(
onConnectionError(
"The WebSocket server speaks old WebSocket protocol, " +
"which is not supported by web-socket-js. " +
"It requires WebSocket protocol HyBi 10. " +
Expand All @@ -383,13 +386,13 @@ public class WebSocket extends EventDispatcher {
}
var replyDigest:String = header["sec-websocket-accept"]
if (replyDigest != expectedDigest) {
onError("digest doesn't match: " + replyDigest + " != " + expectedDigest);
onConnectionError("digest doesn't match: " + replyDigest + " != " + expectedDigest);
return false;
}
if (requestedProtocols.length > 0) {
acceptedProtocol = header["sec-websocket-protocol"];
if (requestedProtocols.indexOf(acceptedProtocol) < 0) {
onError("protocol doesn't match: '" +
onConnectionError("protocol doesn't match: '" +
acceptedProtocol + "' not in '" + requestedProtocols.join(",") + "'");
return false;
}
Expand Down