开发者

Best way to send/receive messages between AIR and .NET console app?

I have a .NET console app that reads info from a USB stick and spits it out. I have an AIR app that listens to it an开发者_Go百科d processes the information.

My problem is that sometimes my air app doesn't seem to process some of the messages, even though the log shows that they were sent from the .net console app.

Here's what I'm doing.

.NET

   Trace.WriteLine("heart," & heartRate & "," & GetTimeStamp() & ",")

I have a bunch of different listeners that spit out information. I'm just sending them through with commas separating the values. I added a comma to the end just to make sure I would spit the array if two lines were picked up at once on the air side (can that even happen?)

AIR

public function ProcessConsoleData(data:String):void{
        var tempArray:Array = data.split(",");
        var pointUpdated:Boolean = false;

        if (tempArray[0] == ("heart")){
            if (_dataModel.DeviceHeartRate.IsDeviceAvailable != true){
                _dataModel.DeviceHeartRate.IsDeviceAvailable = true;
            }

            _dataModel.DeviceHeartRate.HeartRate = int(tempArray[1]);
            _dataModel.DeviceHeartRate.LastUpdate = tempArray[2] as Date;

        }

The process console data function continues like that with about 25 else if statments with different values for tempArray[0] (Yes I know the 'right' thing to do is use a case statement but I like it with else ifs).

Data comes at the app pretty fast. Sometimes just 100ms or maybe less (haven't done any benchmarks). Sometimes the air app won't process the data that's sent. I don't know why and it's hard to debug.

Does anyone have a better way to maintain message fidelity from .NET to AIR? Maybe someone can see a hole in my logic?

Thanks.

-Nate


I was having the same problem and what is happenig is when the answers are sent to Air very fast, through a Console.WriteLine, it may happen that two or more answers are written. Your method "ProcessConsoleData" will have to be further refined, for example by split by "\ r \ n" the input string. After that split you already have individual responses.


Which method do you use? Two apps can be connected through local network, but there is simpler way. AIR can run console app itself with NativeProcess and communicate with it via stdin|stdout. This makes console application child process of AIR app (AIR cannot connect to running console app this way).


Yo, I expect a nice +1 for this answer:)

We used a HttpListener from within a C# app to listen for Air requests. The C# HttpListener (the c# app is run like a local server) is set up to listen on a specific port on the localhost, and the Air app used HTTPService to send requests to this port. The responses were encoded in JSON and we used as3CoreLib for JSON decoding on the flex end (but you could easily use XML). The c# end just recieved some parameters as text, these were the method/class name and arguments. Used Reflection in C# to call the required function based on the string parameters passed in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜