Adobe Air serversocket after base64+sha1 handshake with js client:
PHP Code:
function decodeMask(a){
var encoded=a.splice(4,a.length)
var arr_of_keys=a.splice(0,4)
var str
str=""
for(var i=0;i<encoded.length;i++){
var key = arr_of_keys[i % 4]
str += String.fromCharCode(encoded[i] ^ key)
}
return str;
}
function byteArrayToArray(a){
var arr=[]
for(var i=2;i<a.length;i++){
arr.push(a[i])
}
return arr
}
function onClientSocketData(e:ProgressEvent){
var buffer:ByteArray = new ByteArray();
e.currentTarget.readBytes(buffer, 0, e.currentTarget.bytesAvailable);
trace(decodeMask(byteArrayToArray(buffer)))//unmasked websocket messages
}
javascript client > messages AIR server:
PHP Code:
<html>
<script>
var exampleSocket = new WebSocket("ws://localhost:80");
exampleSocket.onopen = function (event) {
console.log("open");
setTimeout(test,1000);
};
exampleSocket.onmessage = function (event) {
alert(event.data);
}
function test(){
exampleSocket.send('hello AIR server');
setTimeout(test,1000);
}
</script>
</html>