Tuio Flash Blog

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 or newer Air 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 four functions you have to implement:

  1. function addListener(listener:IOSCConnectorListener):void;
  2.                
  3. function removeListener(listener:IOSCConnectorListener):void;
  4.                
  5. function sendOSCPacket(oscPacket:OSCPacket):void;
  6.  
  7. function close():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:

  1. 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:

  1. //packet is the ByteArray containing the raw OSCPacket
  2. for each(var l:IOSCConnectorListener in this.listeners) {
  3.    if (OSCBundle.isBundle(packet)) {
  4.       l.acceptOSCPacket(new OSCBundle(packet));
  5.    } else if (OSCMessage.isMessage(packet)) {
  6.       l.acceptOSCPacket(new OSCMessage(packet));
  7.    } else {
  8.       //error handling
  9.    }
  10. }

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();

Comments (15) Trackbacks (0)
  1. 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

  2. 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.

  3. 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

  4. 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 ;)

  5. Hey Gimmix,

    I’ve been trying for a couple hours now, but I can’t seem to see to get the connector to work. I set the Local Playback security to “Access Network Only”. I installed the kinect drivers, green light is on and flashing. I ran udp-flashlc-bridge-win.exe to default port of 3333. And I put this basic code in my flash cs5 on the first and only frame.

    import flash.net.LocalConnection;
    import flash.utils.ByteArray;

    var connection:LocalConnection = new LocalConnection();
    connection.connect(“_MyConnection”);
    connection.allowDomain(‘*’);
    connection.client = this;

    function dispatchPacket(data:Object):void{
    if (data is ByteArray) {
    var bytes:ByteArray = data as ByteArray;
    trace(“received ” + bytes.length + ” bytes.”);
    }
    }

    I’m not getting any errors but I’m also not receiving any packets. What did I miss? Thanks

  6. If I understand your answer correctly you try to implement an LocalConnection Connector. Actually you don’t have to, that is what the org.tuio.connectors.LCConnector is for ;)
    Also the udp-lc-bridge only sends its data to a LocalConnection named “_OscDataStream”.

  7. So when I run this out of my command line
    udp-flashlc-bridge-win.exe -c _MyConnection -m dispatchPacket
    the connection is actually named “OscDataStream” not “_MyConnection”

    I’m trying to work out the steps to get this working in my head so bear with me.
    1. Install Kinect Drivers (done)
    2. Launch udp-flashlc-bridge-win in command line as above?
    3. Run the TuioManager as3 code as is and we should be good?

    Or are there some other settings or software I need?

  8. I still get this error ” ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"] ” I’m guessing I just don’t know how to set up the connector.

  9. Ah I just noticed you used the demo code from gkaindl’s upd-lc bridge website. That actually should work even without my library. If you use the LCConnector you simply have to run the bridge without any arguments ad it will default to the right values to work with the library.

    The ioerror looks like you are trying to use the TCPConnector. Make sure your bridge/tracker is already running when you start your flash application.

  10. I got same error
    ” ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"] ”
    I am trying to use TCP connector

    and Bridge is running before I start my flash application.

  11. Make sure you have the right port set up. Which bridge are you using?

  12. Unfortunately, as far as I know neither Georg Kaindl’s nor Mehmet Akten’s TCP bridge work with the TCP implementation of tuio-as3.

  13. Hi Gimmix,
    I am trying to use your library for writing multitouch application and want to test with the standard TuioSimulator.
    I am using TCP Connector with host as 127.0.0.1 and port as 3333 in my as3 class.

    However it gives me
    ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error. URL: 127.0.0.1"]
    error.

    Can you please help

  14. The TuioSimulator doesn’t support TCP so I would suggest using the UDPConnector or a bridge.

  15. Has this happened to anyone? I’m trying to build out an application in Flex, making an AIR app, connected via UDP.

    It’ll connect just fine once, then I’ll close it. The 2nd and 3rd time I try to run it, it give me this error: Error #2002: Operation attempted on invalid socket.

    Then the 4th time, it’ll run properly again.

    I’ve tried to force the connection to close with .close() before the app closes to clear the socket, but the command isn’t closing the connection.


Leave a comment


No trackbacks yet.