theturtle32 / as3websocket Goto Github PK
View Code? Open in Web Editor NEWActionScript 3 WebSocket client implementation for the final WebSocket Draft RFC6455
License: Apache License 2.0
ActionScript 3 WebSocket client implementation for the final WebSocket Draft RFC6455
License: Apache License 2.0
Hello,
I'm unable to get a working example for interfacing with socket.io/engine.io.. Is there a working example somewhere? I've tried many things, but transport errors, missing protocols and destroyed upgrades are all I came up with...
Nicolas
connect tornado 4.0.2 websocket, then 403 error.
Hi,
I used this for quite a while in my project. Works great!
However, we are now moving our server behind a CDN which allow only port 80 and 443.
This meaning that my local policy server that run under port 843 will not work any more, as the client will be block by the CDN.
So if client ask bar.foo.com --> resolve to the IP address of the CDN --> open sessions to port 80 or 443 --> goes to my origin server--> hit my server --> get to the web server --> hit back to the client.
Going into wireshark I can see that the client is trying to open port to 843 with the IP address of CDN server. This off course will not work as it get block by the CDN.
If I pass the CDN (by changing my hosts file) everything is working, as I have Policy Server running under the port 843.
Is there any way to configure my flash swf files to work with different policy server?
I tried the System.security.loadPolicyFile options but it is not seems to be working.
Any Idea?
Thank you.
Hi,
For my purpose, I used Gsolo / Crypto / Sha 1 (http://gsolofp.blogspot.com/2006/01/actionscript-3-md5-and-sha1.html)
for the handshake, cuz my phpServer, send sha1 in raw format (binary 20 lenght)
Description: Implicit coercion of a value of type Boolean to an unrelated type Number.
Resource: Hex.as
Path: /AS3WebSocket/src/com/hurlant/util
Location: line 23
Type: Flex Problem
"if (hex.length&1==1)" May be as3 complier is more strictly in new version...
if ((hex.length&1)==1) is ok
http://stackoverflow.com/questions/20338864/as3websocket-library-sha1-error
I am trying to use https://github.com/Worlize/AS3WebSocket library. When I create Flex project everything ok, but when I create AS3 project it can't connect to a websocket server. Function SHA1.hashToBase64 (adobe.crypto library) inside Websocket class throws error:
[SWF] TestWS.swf - 506,881 bytes after decompression
typecheck com.adobe.crypto::SHA1$/hashToBase64()
outer-scope = [global Object$]
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} ()
0:debugfile "/Users/turtle/work/as3corelib/project/src;com/adobe/crypto;SHA1.as"
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} ()
2:debugline 100
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} ()
4:getlocal0
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {} (com.adobe.crypto::SHA1$~[O])
5:pushscope
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {com.adobe.crypto::SHA1$~[O]} ()
6:pushbyte 0
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {com.adobe.crypto::SHA1$~[O]} (int[I])
8:convert_u
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] *[A]] {com.adobe.crypto::SHA1$~[O]} (uint[U])
9:setlocal 7
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
11:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
16:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
21:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
26:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
31:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
36:debug
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
41:debugline 102
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
43:getglobalscope
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (global~[O])
44:getslot 1
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$[O])
46:getlocal1
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$[O] String[S])
47:callproperty com.adobe.crypto:SHA1::createBlocksFromString 1
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (Array[O])
50:coerce Array
[com.adobe.crypto::SHA1$~[O] String[S] *[A] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (Array[O])
52:setlocal2
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
53:debugline 103
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
55:findpropstrict com.adobe.crypto:SHA1::hashBlocks
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$~[O])
57:getlocal2
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (com.adobe.crypto::SHA1$~[O] Array[O])
58:callproperty com.adobe.crypto:SHA1::hashBlocks 1
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O])
61:coerce flash.utils::ByteArray
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] *[A] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O])
63:setlocal3
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
64:pushstring ""
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (String~[S])
66:debugline 109
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (String~[S])
68:coerce_s
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] *[A] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (String~[S])
69:setlocal 4
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
71:debugline 110
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
73:getlocal3
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O])
74:pushbyte 0
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (flash.utils::ByteArray[O] int[I])
76:setproperty position
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
78:debugline 111
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
80:pushbyte 0
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I])
82:convert_i
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] *[A] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I])
83:setlocal 5
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
85:jump 129
------------------------------------
MERGE FIRST B129: [com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
------------------------------------
B129: [com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
129:getlocal 5
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I])
131:getlocal3
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I] flash.utils::ByteArray[O])
132:getproperty length
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (int[I] uint[U])
134:iflt 89
------------------------------------
MERGE FIRST B89: [com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
------------------------------------
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
138:debugline 117
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} ()
140:findpropstrict mx.utils::Base64Encoder
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (Object~[A])
142:constructprop 14 0
[com.adobe.crypto::SHA1$~[O] String[S] Array[O] flash.utils::ByteArray[O] String~[S] int[I] *[A] uint[U]] {com.adobe.crypto::SHA1$~[O]} (*[A])
145:coerce mx.utils::Base64Encoder
Connection Failure: There was an error while parsing the following HTTP Header line:
Sec-WebSocket-Accept: k9NwkeRGtpHKwr+kcSk29tHaAbs=
Disconnected
Its not connecting ...
Am connecting to a websocket
var net = require('net');
var http = require('http');
http.globalAgent.maxSockets = 1000;
var server_port = 4000;
function policy() {
var xml = '\n\n\n';
xml += '\n';
xml += '\n\0' ;
return xml;
}
console.log("server started");
//var WebSocketServer = require('/root/node_modules/ws').Server
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({ port: server_port });
wss.on('connection', function connection(ws)
{
console.log("connection established");
ws.on('message', function incoming(message)
{
console.log(message);
if(message == '<policy-file-request/>\0')
{
var x = policy();
ws.send(x);
return;
}
});
ws.on('close', function() {
});
ws.on('error', function() {
});
});
what could be the issue?
Is Deflate supported in the main branch?
This line does not compile
websocket.enableDeflateStream = true;
1119: Access of possibly undefined property enableDeflateStream through a reference with static type com.worlize.websocket:WebSocket.
There is no such variable in the class, is that how it's meant to be?
I get a connected message when connecting to a socketIO server but then an immediate disconnect.
Any suggestions? This is my complete message
Connecting to 192.168.4.134 on port 3000
Socket Connected
GET / HTTP/1.1
Host: 192.168.4.134:3000
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: ZnyGKnse5Tsdr6znXQKGSA==
Origin: *
Sec-WebSocket-Version: 13
Sec-WebSocket-Protocol: lws-mirror-protocol
Socket Disconnected
Websocket closed.
Are these client/server pairs compatible?
Are these client/server pairs compatible?
I'm trying connect to Spring Boot server (v1.4.2, Tomcat 8.5.6) valid CA signed certificate (SHA256withRSA, SHA1withRSA, 2048) and GOT ALERT! type=40, which looks like handshake issue. Any insight is appreciated.
The code should be updated (perhaps on a separate branch?) to use the new native SecureSocket class available in Air and introduced in Flash Player 11.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SecureSocket.html
I would like to connect to a websocket server (Autobahn), and then subscribe to a channel.
When I use this lib:
websocket = new WebSocket("wss://api.domain.com", "*", "wsservice");
websocket.addEventListener(WebSocketEvent.CLOSED, handleWebSocketClosed);
websocket.addEventListener(WebSocketEvent.OPEN, handleWebSocketOpen);
websocket.addEventListener(WebSocketEvent.MESSAGE, handleWebSocketMessage);
websocket.addEventListener(WebSocketErrorEvent.CONNECTION_FAIL, handleConnectionFail);
websocket.connect();
--- then ---
protected function handleWebSocketOpen(event:WebSocketEvent):void {
websocket.sendUTF(JSON.stringify({
"type": "subscribe",
"channels": ['channel']
}));
}
However when I try to connect, I get the following error:
I DONT KNOW HOW TO HANDLE DER stuff of TYPE 12
Connection Failure: An HTTP response code other than 101 was received. Actual Response Code: 400 HTTP Origin header invalid: No host part in Origin '*'
It seems that little-endian bytearrays are sent as big-endian. Is their a way for me to change that?
Thanks!
I made a multiplayer game and used this and it works great but when I embed the swf to my site it will no longer connect. When I click connect nothing happens for 5 seconds then it runs the onWebSocketClosed event handler.
event.message also returned null
Hi,
Im having a problem trying to stream microphone input using webSockets.
In my my micSampleDataHandler I'm converting the input and sending it through websocket.sendBytes(bytes) method.
While testing in emulator on desktop everything seems to work fine, but once i start testing on Android device websocket.sendBytes(bytes); seems to block the micSampleDataHandler. its looks like it stops the thread.
It does execute, but it takes much longer time. sending1 trace gets executed, but it takes a while to execute sending2 trace.
Do you maybe know what could be the cause of this? Shouldn't this be async?
This is my mic handler:
function micSampleDataHandler(event:SampleDataEvent):void
{
var bytes:ByteArray = new ByteArray();
while(event.data.bytesAvailable)
{
var sample:Number = event.data.readFloat();
var integer:int;
sample = sample * 32768 ;
if( sample > 32767 ) sample = 32767;
if( sample < -32768 ) sample = -32768;
integer = int(sample);
bytes.writeShort(integer);
}
trace("sending1");
bytes.position = 0;
websocket.sendBytes(bytes);
trace("sending2");
}
when I use the client to connect my websocket server , I got an error "TLSEngine shutdown triggered by Error: Excessive TLS Record length: 20527". then disconnected. I do not why.
I using AS3WebSocket to connect socket.io server (ver 0.9+)
And I cannot connect my server, but when I change SHA1 library like #1 suggest, it work correctly.
I also try add as3crypto
and use its' SHA1 library, and it also work correctly.
Any plans to make the server in as3?
Can you please guys give me a hand here?
My Deno WebSocketServer dispatches the "close" event with the Javascript built-in WebSocket when I close the HTML page.
But not with the AS3WebSocket lib when I close the NativeWindow. I even tried listening to the NativeProcessErrorEvent.ERROR event and force the websocket to close manually. The other events dispatch ok (new message and new client connection).
Thanks, cheers.
I'm trying to execute this part of the example:
websocket = new WebSocket("wss://echo.websocket.org", "*", "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();
and I get an error:
Connection Failure: The server can not respond in any of our requested protocols
Disconnected
and in the trace output I have:
I DONT KNOW HOW TO HANDLE DER stuff of TYPE 12
Do you know what the problem might be?
Don't want to nag, just curious if it's going to happen.
Dear sir,
I'm setup websocket server by using AutoBahn|Python on Amazon EC2 successfully connected to Javascript websocket.
However, I'm facing the problem on connecting to AS3WebSocket.
When I test the AS3 project as debug from FlashDevelop the WebSocketErrorEvent.CONNETION_FAIL Occur with following text
An HTTP response code other than 101 was received. Actual Response Code: 400 missing port in HTTP Host header '54.251.48.207' and server runs on non-standard port 10001 (wss=False)
When I run the project on web browser, WebsocketEvent.CLOSED occur without WebSocketErrorEvent.CONNECTION_FAIL
same as when I upload the project to Amazon EC2.
I'm not good in Networking background, so Please guide me through out the problem, Please.
Best Regards,
Chet Chetchaiyan
Does this lib supports working under proxy?
When use ws.ping(),A null pointer error occurred.
Sometime my as3 crashes throwing the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert com.worlize.websocket::WebSocketErrorEvent@a47b661 to com.worlize.websocket.WebSocketEvent.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.