The Connectors
To make it as easy as possible to change how the tuio data should be received from the tracker the connectors were conceived.
A connector is basically an implementation of the org.tuio.osc.IOSCConnector interface. Why "IOSCConnector" and not "ITuioConnector" you might ask well that is due to the fact that tuio is based on OSC (opensoundcontrol.org). That's why the tuio-as3 library contains a full osc parser which receives it's data via the connectors and sends the parsed messages to the TuioClient.
Okay now after this little excursion on the library's architecture back to the actual connectors.
Included Connectors
There are currently three Connectors included within the tuio-as3 library.
UDPConnector
This connector can be used to receive and send tuio/osc messages via UDP. This is the method which is mostly used to send OSC/Tuio data. This connector can only be used within Air2.0 projects.
TCPConnector
This connector can be used to receive tuio/osc messages via TCP in it's binary format just like it is sent via UDP. It supports both straight forward OSCPacket to TCP stream writing and also the method suggested by the OSC specification of using additional integers between separate OSCPackets.
This connector should work with all versions of Flash supporting as3.
Because TCP has mainly been used to send tracking data this connector might not always work due to various reasons. Currently there are two known incompatibilities.
- The tuio data is sent via TCP but in a XML format. -> e.g. oscar, flosc
- Binary TCP doesn't actually send Tuio -> e.g. CCV
LCConnector
This connector can be used to receive and send via Flash's LocalConnection feature which uses a shared memory file to send messages between Flash movies. There is currently one udp->lc bridge (http://gkaindl.com/software/udp-flashlc-bridge) that supports this.
In theory this method should be the fastest if implemented by a tracker itself but currently has its limitations because there is no open documentation about how LocalConnection actually works so developers have to rely on reverse engineering.
This connector could be very interesting in a scenario using only the osc features of the library where one Flashmovie handles the interface and the other e.g. synthesizes audio according to the received OSCMessages.
Writing you own Connectors
As I already mentioned in the introduction in order to create your own connector you simply have to implement the IOSCConnector interface.
The IOSCConnector interface defines three functions you have to implement:
-
function addListener(listener:IOSCConnectorListener):void;
-
-
function removeListener(listener:IOSCConnectorListener):void;
-
-
function sendOSCPacket(oscPacket:OSCPacket):void;
The first two functions are needed for the receiving aspect of the connector and can be copied from the already existing connectors but bysically they are simple array operations. If you have a quick look at the IOSCConnectorListener interface you will see that it only consists of one function:
-
function acceptOSCPacket(oscPacket:OSCPacket):void;
You have to call this function on all IOSCConnectorListeners added via your implementation of the addListener(...) function if your connector receives an OSCPacket. If the data you received is a raw binary array that is formatted as specified in the OSC specification you can simply use the OSCBundle or OSCMessages constructor to parse the binary array. This could look like the following:
-
//packet is the ByteArray containing the raw OSCPacket
-
for each(var l:IOSCConnectorListener in this.listeners) {
-
if (OSCBundle.isBundle(packet)) {
-
l.acceptOSCPacket(new OSCBundle(packet));
-
} else if (OSCMessage.isMessage(packet)) {
-
l.acceptOSCPacket(new OSCMessage(packet));
-
} else {
-
//error handling
-
}
-
}
The function "sendOSCPacket" has to be fully implemented if your connector should be able to send data. As you can see you get an OSCPacket object but you don't have to worry about converting that into a binary array if you happen to need that for your connector. The OSCPacket already does that for you if you call oscPacket.getBytes();
July 12th, 2010 - 17:57
Hi, I have a problem when playing around with the GestureManagerExample.
Here is the output:ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket 错误。 URL: 127.0.0.1"] What’s wrong with the connector?
My environment is mac os 10.6, flash cs5.THX
July 13th, 2010 - 21:17
You have to make sure, that the tracker is already running when you start your flash file. Also make sure that the right port is configured both at you tracker and in your project. The standard port the TCPConnector uses is 3333.
July 20th, 2010 - 08:49
thanks,I chang TCPConnector to UPDConnector, it works with Tongseng in mac trackpad.
But when I put 4 or 5 finger on the trackpad, the GestureManagerExample swf runs really slowly.(same in using TCPConnector)
what should I do to improve the efficiency. THX
July 20th, 2010 - 19:33
Mh 5 fingers works fine for me on windows @2×2.5ghz. There are multiple possible causes. The primary probably the humble performance of flash/air on macosx. I’ll try do some performance tests on my old macbookpro and let you know if I have something