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:
-
function addListener(listener:IOSCConnectorListener):void;
-
-
function removeListener(listener:IOSCConnectorListener):void;
-
-
function sendOSCPacket(oscPacket:OSCPacket):void;
-
-
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:
-
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
January 5th, 2011 - 21:28
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
January 6th, 2011 - 01:17
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”.
January 6th, 2011 - 01:28
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?
January 6th, 2011 - 01:37
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.
January 6th, 2011 - 19:33
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.
February 20th, 2011 - 12:43
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.
February 20th, 2011 - 17:46
Make sure you have the right port set up. Which bridge are you using?
August 1st, 2011 - 16:54
Unfortunately, as far as I know neither Georg Kaindl’s nor Mehmet Akten’s TCP bridge work with the TCP implementation of tuio-as3.
August 5th, 2011 - 12:22
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
August 9th, 2011 - 23:03
The TuioSimulator doesn’t support TCP so I would suggest using the UDPConnector or a bridge.
December 6th, 2011 - 23:51
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.
April 5th, 2012 - 23:07
I’m just trying to get OSC into flash. That’s it. That’s all I need to do. Your implementation description isn’t enough for me. I’ve spent all day on this now. I have it up and working with TuioPad but what I really want it working with is TouchOSC so I can have knobs to tune my game I’m writing with as players playtest.
Is there a code example of this? It seems like such a simple request.
Here’s what I have so far…
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import org.tuio.TuioClient;
import org.tuio.TuioEvent;
import org.tuio.TuioTouchEvent;
import org.tuio.connectors.LCConnector;
import org.tuio.connectors.UDPConnector;
import org.tuio.debug.TuioDebug;
import org.tuio.legacy.TouchEvent;
import org.tuio.osc.IOSCConnector;
import org.tuio.osc.IOSCConnectorListener;
import org.tuio.osc.IOSCListener;
import org.tuio.osc.OSCEvent;
import org.tuio.osc.OSCMessage;
import org.tuio.osc.OSCPacket;
import org.tuio.osc.IOSCConnectorListener;
public class OSCExample extends Sprite implements IOSCConnector
{
public function OSCExample()
{
var tc:TuioClient = new TuioClient(new UDPConnector
(“192.168.0.12″, 3333));
tc.addListener(TuioDebug.init(stage));
//displays touches
//draw rect
var myRect:MovieClip = new MovieClip();
myRect.graphics.beginFill(0x6633cc);
myRect.graphics.drawRect(0,0,200,200);
//add listener to rect
myRect.addEventListener(TuioTouchEvent.TOUCH_DOWN, onTouch);
stage.addChild(myRect);
addEventListener(OSCEvent.OSC_DATA, addListener);
}
public function addListener(listener:IOSCConnectorListener):void
{
//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
}
}
}
// public function receiveOSCMessage(e:OSCMessage):void {
// trace(e);
// }
public function removeListener(listener:IOSCConnectorListener):void {
}
public function sendOSCPacket(oscPacket:OSCPacket):void {}
public function close():void {}
public function onTouch(e:TuioTouchEvent):void {
trace(“touchdown!”);
}
}
}
April 6th, 2012 - 18:21
Well it looks like TouchOSC doesn’t send TUIO commands. So the best way to do this is to implement an IOSCListener which handles the OSC messages sent by TouchOSC. You then only have to start a OSCManager instead of the TuioManager and add your implementation as a msg listener via OSCManager.addMsgListener. You can also add it via OSCManager.addMethod and specify a single OSC command address.