AS3WebSocket is a WebSocket client implementation for the final WebSocket Draft RFC6455. The client only works with RFC6455 compliant servers, as a result it will not work with draft-75 or draft-76/-00 servers that are deployed on the internet.

Among its features is the wss:// TLS support with As3 Crypto library and the ability to send and receive fragmented messages. The library has two demos to test subprotocols from Andy Green’s libwebsockets test server, the dumb-increment-protocol and the lws-mirror-protocol.


var websocket:WebSocket = new WebSocket("wss://localhost:4321/foo?bing=baz", "*", "my-chat-protocol");
websocket.enableDeflateStream = true;
websocket.addEventListener(WebSocketEvent.CLOSED, handleWebSocketClosed);
websocket.addEventListener(WebSocketEvent.OPEN, handleWebSocketOpen);
websocket.addEventListener(WebSocketEvent.MESSAGE, handleWebSocketMessage);
websocket.addEventListener(WebSocketErrorEvent.CONNECTION_FAIL, handleConnectionFail);

function handleWebSocketOpen(event:WebSocketEvent):void {
  websocket.sendUTF("Hello World!\n");

  var binaryData:ByteArray = new ByteArray();
  binaryData.writeUTF("Hello as Binary Message!");

function handleWebSocketClosed(event:WebSocketEvent):void {

private function handleConnectionFail(event:WebSocketErrorEvent):void {
  trace("Connection Failure: " + event.text);

function handleWebSocketMessage(event:WebSocketEvent):void {
  if (event.message.type === WebSocketMessage.TYPE_UTF8) {
    trace("Got message: " + event.message.utf8Data);
  else if (event.message.type === WebSocketMessage.TYPE_BINARY) {
    trace("Got binary message of length " + event.message.binaryData.length);
Misc . URL.