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.
Sample
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); websocket.connect(); function handleWebSocketOpen(event:WebSocketEvent):void { trace("Connected"); websocket.sendUTF("Hello World!\n"); var binaryData:ByteArray = new ByteArray(); binaryData.writeUTF("Hello as Binary Message!"); websocket.sendBytes(binaryData); } function handleWebSocketClosed(event:WebSocketEvent):void { trace("Disconnected"); } 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); } }
RT @as3gamegears: New: AS3WebSocket (WebSocket client implementation for the final draft RFC6455) http://t.co/ivQx2a8pK3 #as3 #flash #gamed…