Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
96fb998
created new handshake protocol to retrieve sessionid and timeouts
Jul 22, 2011
dcc240e
wired in messages, json decoding and custom events
Jul 25, 2011
17d33b3
removing unused import
Aug 28, 2011
5b694c7
updated readme
Aug 28, 2011
a1b8a89
added Connection_error to replace trace for connection timeout and ha…
Sep 15, 2011
bbe69ad
added close event for close message
Oct 13, 2011
a1cb631
updated read me
Oct 13, 2011
7cfc83c
Updated from recommendation in issue #6 to resolve browser cache issue
Dec 7, 2011
ac1a749
Add the acknowledgement functionality from the socket.io spec
bwillard Jan 17, 2012
204f00e
Merge pull request #12 from bwillard/0.7.x
Jan 17, 2012
87f6c7e
Make the flashsocket be able to support https connections
bwillard Jan 19, 2012
f3c43a3
Merge pull request #13 from bwillard/0.7.x
Jan 20, 2012
171bbdd
because web-socket-js use encodeURIComponent(), so change Flashsocket…
catoc Mar 1, 2012
bc2d2de
Merge pull request #14 from catoc/0.7.x
Apr 25, 2012
584eadf
Initial update with changes made to work as PURE AS3 release
jimib Mar 4, 2013
cb20bdc
Completed transition to using com.jimisaacs.data.URL - this is first …
jimib Mar 4, 2013
781a168
Compiled the swc using Flex 4.6 for purpuse of testing and ease of us…
jimib Mar 4, 2013
53b6be5
Quick and dirty implementation of Channels, now when connect message …
jimib Mar 14, 2013
5231e62
Fixed bug, was splitting message from server on ':' and forgot that t…
jimib Mar 14, 2013
8eb36f5
Minor tweaks - but mostly debugging
jimib May 21, 2013
571e5b8
Added the debugger module
jimib May 21, 2013
9c61361
adds all important clone method to FlashSocketEvent.as
redannick Dec 19, 2013
30abed1
adds passing of data to cloned event
redannick Dec 20, 2013
f10a813
Merge pull request #1 from redannick/0.7.x
jimib Mar 4, 2014
20e47be
Updating gitignore to hide the FlashBuilder metadata file
jimib Mar 4, 2014
98b03dd
Merge branch '0.7.x' of github.com:jimib/FlashSocket.IO into 0.7.x
jimib Mar 4, 2014
c6ac58c
Rebuilt the precompiled lib
jimib Mar 4, 2014
732e8b7
Updated the README to make the links more legible
jimib Mar 4, 2014
c8ea807
Updated the README to make the links more legible
jimib Mar 4, 2014
050562b
Removed unwanted trace statements. Removed dependence on MonsterDebug…
jimib Mar 4, 2014
560545d
updates to latest Websocket to try to get around ssl issue. Still had…
redannick May 28, 2014
f7aac60
adds ability to pass querystring parameters
redannick Jun 10, 2014
1102c4c
removes trace statements
redannick Jun 10, 2014
dc8538c
works (at least for my purposes, and without binary support) with Soc…
redannick Jul 1, 2014
629079a
updates README.md
redannick Jul 1, 2014
4673382
-Removed non-existent import
Cleod9 Jul 13, 2014
ac4cf8c
Merge pull request #1 from Cleod9/1.0.x-cleod9-event-fix
redannick Jul 14, 2014
4d771fa
add 'query' param to FlashSocket
chatziko Oct 16, 2015
f8adf87
add FlashSocketEvent.ERROR for handling server-side errors
chatziko Oct 18, 2015
9b5cef6
disable Encoder and Decoder trace's
chatziko Oct 18, 2015
68fc14c
update WebSocket to support native SecureSocket
chatziko Oct 20, 2015
321e039
remove hurlant crypto lib
chatziko Oct 20, 2015
5faa6cb
WebSocket: set 10s default timeout, 1s is not enough to load master p…
chatziko Oct 21, 2015
258743f
remove loadDefaultPolicyFile
chatziko Oct 21, 2015
3d408a6
correctly add cb to send ack to messages
chatziko Dec 12, 2015
68e5d47
bugfix: correctly clean ack callbacks
chatziko Dec 16, 2015
f86b8ca
use AS3WebSocket instead of web-socket-js
chatziko Jan 7, 2016
88e55b6
new AS3WebSocket version (use native SecureSocket)
chatziko Jan 8, 2016
0596d8a
support for receiving binary data
chatziko Jan 10, 2016
21b05ee
support for sending binary data
chatziko Jan 12, 2016
60384ba
use native JSON
chatziko Jan 18, 2016
6f28716
remove initial polling request, use only WebSocket
chatziko Jan 19, 2016
3eac072
extend EventDispatcher instead of implementing IEventDispatcher
chatziko Jan 19, 2016
137016b
emit buffered messages after dispatching CONNECT
chatziko Jan 20, 2016
f8b0ef4
add Makefile, new build
chatziko Jan 21, 2016
1fd12e5
new README
chatziko Jan 21, 2016
88a3579
properly close() if called while connecting
chatziko Jan 26, 2016
32668e5
several improvements in disconnect logic
chatziko Jan 30, 2016
2107e62
add sample client and server
chatziko Feb 20, 2016
e110e1d
sample: small changes
chatziko Feb 21, 2016
33faa90
allow passing certs array to the constructor
chatziko Apr 13, 2016
e694be3
initial transport support, separate WebSocket code
chatziko May 30, 2016
c891b64
add polling transport
chatziko Jun 1, 2016
5e72872
separate Engine class
chatziko Jun 2, 2016
692c4f1
property implement transport upgrades
chatziko Jun 2, 2016
3df52fe
sample: log transport, delay server message to allow upgrade
chatziko Jun 2, 2016
3d6a65e
new build
chatziko Jun 2, 2016
ee2a677
update README
chatziko Jun 2, 2016
95bfba7
smaller timestamps using yeast, send qs only on the first connection
chatziko Jun 3, 2016
f61941c
restore sending the full query in all requests
chatziko Jun 8, 2016
04540dd
add uri public property
chatziko Jun 8, 2016
e8cc84a
new build
chatziko Jun 8, 2016
1d00993
Polling: explicit string conversion to avoid errors
chatziko Jun 12, 2016
773b393
add transport fallback support
chatziko Jun 14, 2016
9f8ea1b
add connectTimeout option
chatziko Jun 27, 2016
0fedcdb
improved logging
chatziko Sep 21, 2016
26b9851
new build
chatziko Sep 21, 2016
6cd5d78
Merge branch 'polling-support' into 1.0.x
chatziko Sep 21, 2016
d0e20a3
new AS3WebSocket, adds limited support for permessage-deflate
chatziko Sep 22, 2016
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.actionScriptProperties
.flexLibProperties
.project
.settings/*
.metadata

sample/node_modules
sample/npm-debug.log
sample/client.swf
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "library/support/web-socket-js"]
path = library/support/web-socket-js
url = git://github.com/simb/web-socket-js.git
[submodule "support/web-socket-js"]
path = support/web-socket-js
url = git://github.com/simb/web-socket-js.git
[submodule "libs/AS3WebSocket"]
path = libs/AS3WebSocket
url = https://github.com/chatziko/AS3WebSocket.git
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
find = $(foreach dir,$(1),$(foreach d,$(wildcard $(dir)/*),$(call find,$(d),$(2))) $(wildcard $(dir)/$(strip $(2))))

FLEX_HOME?=/usr/local/apache-flex-sdk

all: bin/Flash-Socket.IO.swc
sample: sample/client.swf

bin/Flash-Socket.IO.swc: $(call find, src, *.as)
@mkdir -p bin
$(FLEX_HOME)/bin/compc \
--source-path=./src \
--source-path=./libs/AS3WebSocket/AS3WebSocket/src \
--library-path=./libs \
--include-classes=com.pnwrain.flashsocket.FlashSocket \
--debug=true \
--output=$@

sample/client.swf: sample/client.as bin/Flash-Socket.IO.swc
$(FLEX_HOME)/bin/mxmlc \
--library-path=bin/Flash-Socket.IO.swc \
--debug=true \
--output=$@ \
sample/client.as

54 changes: 48 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
# FlashSocket.IO

Flash library to facilitate communication between Flex applications and Socket.IO servers.
Flash client for [Socket.IO](http://socket.io/) version 1.0 and above. Connects
solely through WebSocket and supports binary data and native TLS (through
[SecureSocket](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SecureSocket.html)).

The actual websocket communication is taken care of by my fork of gimite/web-socket-js project.
## Notes for this fork

This project wraps that and facilitates the hearbeat and en/decoding of messages so they work with Socket.IO servers
This fork is based on
[redannick/FlashSocket.IO](https://github.com/redannick/FlashSocket.IO) (which
itself is based on
[jimib/FlashSocket.IO](https://github.com/jimib/FlashSocket.IO)) and contains
several improvements and bugfixes:

# Checkout
* support for both polling and websockets
* upgrade support (by default connect with polling and upgrade to websocket later)
* support for sending/receiving binary data (as
[ByteArray](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/ByteArray.html))
* use [my fork](https://github.com/chatziko/AS3WebSocket) of
[AS3WebSocket](https://github.com/theturtle32/AS3WebSocket), with the following improvements:
* use native SecureSocket for TLS (faster, more sucure, reduces swc size by 86%)
* limited support for [permessage-deflate](https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-19) compression
(accept compressed messages from the server, although the client never compresses itself)
* separate engine.io client code
* add ERROR event for handling server-side errors
* bugfix: propertly add callback to messages for sending ACK
* bugfix: properly clean ACK callbacks
* bugfix: emit buffered message after dispatching the CONNECT event
* bugfix: stop heartbeat timer when socket abruptly closes
* bugfix: dispatch DISCONNECT when connecting is manually close()ed
* use native [JSON](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/JSON.html)
* remove CLOSE event (unclear semantics), use DISCONNECT instead
* add destroy() method (similar to the js socket.io-client)

Because this project makes use of git submodules you must make use of the recursive clone.
Tested with Socket.IO 1.4.

## Sample client and server

A sample [client](./sample/client.as) and [server](./sample/server.js) are provided.
To try them:

* Install dependencies and start server
```
cd sample
npm install
npm start
```

* Compile the client, eg with ```mxmlc```:
```
mxmlc --library-path=bin/Flash-Socket.IO.swc sample/client.as
```

* Open [http://localhost:3000/](http://localhost:3000/)

git clone --recursive git://github.com/simb/FlashSocket.IO.git
Binary file added bin/Flash-Socket.IO.swc
Binary file not shown.
1 change: 1 addition & 0 deletions libs/AS3WebSocket
Submodule AS3WebSocket added at 7f6e6c
Binary file modified libs/as3corelib.swc
100644 → 100755
Binary file not shown.
88 changes: 88 additions & 0 deletions sample/client.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package {

import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.text.TextField;
import flash.utils.ByteArray;

import com.pnwrain.flashsocket.FlashSocket;
import com.pnwrain.flashsocket.events.FlashSocketEvent;


public class client extends Sprite {

public var socket:FlashSocket;
public var txt:TextField;

// log in the TextField, via trace, and with console.log
//
public function log(...args):void {
if(socket)
args.unshift(socket.transport)

txt.appendText(args.join(' ') + "\n")

trace(args.join(' '))

if(ExternalInterface.available) {
args.unshift('console.log');
ExternalInterface.call.apply(ExternalInterface, args)
}
}


public function client() {
txt = new TextField();
txt.width = 1000;
txt.height = 1000;
addChild(txt);

FlashSocket.debug = true;

// connect to the same url as the page we're in
var url:String = ExternalInterface.call("window.location.href.toString");
log("connecting to: " + url);

socket = new FlashSocket(url);

socket.addEventListener(FlashSocketEvent.CONNECT, function(e:FlashSocketEvent):void {
log("connected");

log("sending bar")
socket.emit('bar', 'foo', function(ba:ByteArray):void {
log('bar: got back ByteArray: ', ba[0], ba[1]);
});
});

socket.addEventListener('foo', function(e:FlashSocketEvent):void {
var s:String = e.data[0];
var cb:Function = e.data[1];

log("got 'foo' from server with data: " + s);
log("sending back ByteArray with 2 bytes");

var ba:ByteArray = new ByteArray();
ba[0] = 1;
ba[1] = 2;
cb(ba);
})

socket.addEventListener(FlashSocketEvent.DISCONNECT, function(e:FlashSocketEvent):void {
log("disconnect");
});
socket.addEventListener(FlashSocketEvent.SECURITY_ERROR, function(e:FlashSocketEvent):void {
log("security error");
});
socket.addEventListener(FlashSocketEvent.CONNECT_ERROR, function(e:FlashSocketEvent):void {
log("connect error");
});
socket.addEventListener(FlashSocketEvent.IO_ERROR, function(e:FlashSocketEvent):void {
log("io error");
});
socket.addEventListener(FlashSocketEvent.ERROR, function(e:FlashSocketEvent):void {
log("error");
});
}

} // class
} // package
15 changes: 15 additions & 0 deletions sample/client.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>

<html>
<head>
<style>
html, body, #swf { width: 100%; height: 100%; margin: 0; }
object { display:block; }
</style>
</head>
<body>
<object type="application/x-shockwave-flash" data="client.swf" id="swf">
<param name="allowScriptAccess" value="always"/>
</object>
</body>
</html>
10 changes: 10 additions & 0 deletions sample/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "flashsocket-sample",
"version": "0.1.0",
"description": "A sample server to connect using FlashSocket.IO",
"dependencies": {
"express": "^4.13.4",
"policyfile": "chatziko/FlashPolicyFileServer",
"socket.io": "^1.4.0"
}
}
75 changes: 75 additions & 0 deletions sample/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

var fs = require('fs')
var http = require('http')
var https = require('https')
var express = require('express')
var policyfile = require('policyfile')
var ioServer = require('socket.io')


// CONFIGURATION. Set key/cert to enable https
var httpPort = 3000
var httpsPort = 3001
var key // = "...path to key file..."
var cert // = "...path to cert file..."

// basic express app to serve client.html and client.swf
var expressApp = express()
expressApp.use('/', express.static('.', { index: 'client.html' }))

// http server
var masterHttp = http.Server(expressApp)
masterHttp.listen(httpPort, function() {
console.log('listening to port', httpPort)
console.log('open http://localhost:'+httpPort+'/ in your browser')
})

// https server (if key/cert are set)
if(cert) {
var credentials = {
key: fs.readFileSync(key),
cert: fs.readFileSync(cert),
}
var masterHttps = https.Server(credentials, expressApp)
masterHttps.listen(httpsPort)
}

// serve policy file on httpPort, and also on port 843 if we can
var canOpenLowPorts = !process.getuid || process.getuid() == 0
var policyPort = canOpenLowPorts ? 843 : -1

policyfile.createServer().listen(policyPort, masterHttp)
if(cert)
policyfile.createServer().listen(-1, masterHttps)

// socket.io server
var io = new ioServer(masterHttp, {
pingInterval: 5000,
pingTimeout: 5000,
})
if(cert)
io.attach(masterHttps)

io.on('connection', function(socket) {
console.log('client connected')

setTimeout(function() {
console.log('sending foo')
socket.emit('foo', 'bar', function(buf) {
console.log('foo: got back', buf)
})
}, 1000)

socket.on('bar', function(s, cb) {
console.log("got 'bar' from client with data: " + s)
console.log("sending back Buffer with 2 bytes")

cb(new Buffer([1, 2]))
})

socket.on('disconnect', function() {
console.log('client disconnected');
})
})


Loading