Tag Archive for 'AIRServer'

Accessing the kinect in javascript through websockets

Good morning all! (or evening, night, … depending on when you read this post of course). As you might know, I’ve been working on AIRKinect (as3nui.com) and I’ve got a side project AIRServer aswell (which allows you to setup air as a socket server, including websocket support).

Wouldn’t it be fun, to combine these two projects in a demo, so you can access the kinect information through a websocket? That’s exactly what I did. You run a desktop application on your computer, which is responsible for accessing the kinect, and exposing the skeleton information over a websocket. Using a javascript client, which supports websockets, you can connect to that server, and use the skeleton information in the javascript client :-)

In this demo, I’m just rendering the skeleton points in a canvas element, using three.js.

I’ve uploaded the sources and included binary installers for the desktop application (windows 7, OSX Lion). What you’ll need to do is install & launch the desktop application, and click on the “start server” button to listen for websocket connections on the given port. Make sure you’ve got the kinect sdk installed on your computer (windows) or openni on OSX.

Using the javascript client, you connect to your ip (if you’re testing on the same ip, 127.0.0.1 should be fine), and you can start dancing in the canvas element :-).

AIRServer 0.5 – socket byte concatenation

I’ve just finished work on a little update of my AIRServer library (version 0.5, hooray!). Apparently, when you send large chunks of data over the socket (like sending an image to the server, over the socket), it could happen the data is split over multiple packages. This caused errors on the server side.

I’ve fixed that issue, and uploaded an updated version, together with an image-sending-demo. Enjoy!

AIRServer 0.4 – UDP Handling, Chrome 16 websockets & bugfixes

I’ve just finished some updates on my AIRServer library, which enables you to create an AIR app that listens for different inputs such as sockets, websockets and P2P traffic. This gives you the option to create a multi-user game, with different input controllers.

I’ve added a UDP Endpoint, so you can handle UDP traffic aswell now (check out the UDP native extension for AIR mobile, to use UDP on mobile devices). UDP is connectionless, so you can specify a timeout, when we mark a “udp client” as disconnected.

server.addEndPoint(new UDPEndPoint(1236, new NativeObjectSerializer(), 60000));

When you want to send data back over UDP, you’ll need to know the UDP listening port of the client: therefore, the client can send a “PORT” command, with the listening port as data argument:

protected function connect():void
{
	listeningSocket = new DatagramSocket();
	listeningSocket.addEventListener(DatagramSocketDataEvent.DATA, socketDataHandler);
	listeningSocket.bind(9876);
	listeningSocket.receive();
 
	sendingSocket = new DatagramSocket();
	sendingSocket.connect("127.0.0.1", int(port.text));
	currentState = "connected";
}
 
protected function sendInput():void
{
	sendObject({command: "PORT", data: listeningSocket.localPort});
	sendObject(inputField.text);
	inputField.text = "";
}
 
protected function sendObject(o:Object):void
{
	var bytes:ByteArray = new ByteArray();
	bytes.writeObject(o);
	sendingSocket.send(bytes);
}

I’ve also made some arguments optional (such as the message serializers). By default, an AMF endpoint will use a NativeObjectSerializer, websockets will use the JSONSerializer.

server.addEndPoint(new SocketEndPoint(1234, new AMFSocketClientHandlerFactory()));
server.addEndPoint(new SocketEndPoint(1235, new WebSocketClientHandlerFactory()));
server.addEndPoint(new UDPEndPoint(1236, new NativeObjectSerializer(), 60000));
server.addEndPoint(new CocoonP2PEndPoint("be.aboutme.airserver.demos.Messages"));

I’ve fixed some issues with multiple-messages in one packet. This was especially a problem with the websocket listener. The object serializer is now responsible for splitting the input into multiple messages (when necessary). By default, the JSONSerializer used for the websockets, will split messages on the newline (\n) character. Make sure you terminate each message you send from the client with this character, and you should be good to go.

As always, you can download the sources & updated demos to play with. Happy coding!

You can find the latest version here :-)