Open anber500 opened 10 years ago
I'm compiling it on openFl. Here is my code:
package com.berry.eeg;
import flash.display.Sprite;
import flash.events.Event;
import flash.Lib;
import haxe.Json;
import haxe.Timer;
import ru.stablex.net.MsgExtract;
import ru.stablex.net.SxClient;
class Main extends Sprite
{
var inited:Bool;
private var client:SxClient;
/* ENTRY POINT */
function resize(e)
{
if (!inited) init();
// else (resize or orientation change)
}
function init()
{
if (inited) return;
inited = true;
this.client = new SxClient();
client.extract = MsgExtract.extractString.bind("\r");
client.pack = MsgExtract.packString.bind("\n");
client.onMessage = this.onMessage;
client.onConnect = this.onConnect;
client.onDisconnect = this.onDisconnect;
trace('Trying to connect...');
client.connect("localhost", 13854);
//client.connect("localhost", 6437); //Leap
Lib.current.addEventListener(Event.ENTER_FRAME, function(e:Event){
//if socket has events, this method will fire them
client.processEvents();
});
}
function requestPolicy()
{
client.send("<policy-file-request/>");
}
public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, added);
}
function added(e)
{
removeEventListener(Event.ADDED_TO_STAGE, added);
stage.addEventListener(Event.RESIZE, resize);
#if ios
haxe.Timer.delay(init, 100); // iOS 6
#else
init();
#end
}
public static function main()
{
// static entry point
Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
Lib.current.addChild(new Main());
}
public function onConnect() : Void {
trace("CONNECTED");
requestPolicy();
Timer.delay( configure, 1000);
}
function configure()
{
trace("configure...");
client.send(Json.stringify( { "enableRawOutput": true, "format": "Json" } ));
Timer.delay( authorise, 1000);
}
function authorise()
{
trace("authorise...");
client.send(Json.stringify({"appName": "Connect APP", "appKey": "2f54141b4b4c567c558d3a76cb8d715cbde03096"}));
}
public function onDisconnect() : Void {
trace("DISCONNECTED");
}
public function onMessage(msg:String) : Void {
trace(msg);
}
}
This is what I get back :(
ªªÈªªÈªªÈªªÈªªÈªªÈªªÈªªÈ
I have 2 socket servers running. The Thinkgear Connector and Leap Motion socket server.
Thinkgear connector: http://developer.neurosky.com/docs/doku.php?id=thinkgear_connector_tgc
The thinkgear sockets connect on port 13854.
If I connect on the Flash target, it works fine. If I connect with the Neko, Windows targets, the connection succeed, but the incoming data is all gibberish.
I have looked at the code but without being able to "see" what's inside the packets, I'm can't figure out what the format of the data is and why StablexNet can't read the data.
I figured that if Flash is reading the data correctly, then the other targets should ready the data as well?