Adobe AIR desktop application communicate with Processing application

☆樱花仙子☆ 提交于 2019-12-11 11:22:59

问题


I have a Processing application that must talk to a desktop Adobe AIR application. Can anyone suggest the best options considering the following?

If sockets are the answer, which type of Socket, UDP(Datagram Class), ServerSocket or just plain Socket?

-both apps reside on same machine
-latency important, smaller better
-signals being sent are small, consisting of 3 values

-communication is 1 way only, processing TO Adobe AIR


回答1:


On the Processing side you can use oscP5:

import oscP5.*;
import netP5.*;

OscP5 osc;
NetAddress where;

void setup() {
  frameRate(25);text("click to send\nOSC",5,50);

  osc = new OscP5(this,12000);
  where = new NetAddress("127.0.0.1",8082);
}
void draw() {}
void mousePressed() {
  OscMessage what = new OscMessage("/straps");
  what.add(193.4509887695313);
  osc.send(what, where); 
}

In AIR you would use a DatagramSocket indeed. Luckily you can use something that with OSC packets like TUIO AS3's UDPConnector. Here's a basic as3 sample:

package
{
    import flash.display.Sprite;
    import flash.utils.getDefinitionByName;

    import org.tuio.connectors.UDPConnector;
    import org.tuio.osc.*;

    public class BasicOSC extends Sprite implements IOSCConnectorListener
    {
        private var oscSocket:UDPConnector;
        private const OSCSERVER:String = "127.0.0.1";
        private const PORT:int = 8082;

        public function BasicOSC()
        {
            try{    
                oscSocket = new UDPConnector(OSCSERVER,PORT);
                oscSocket.addListener(this);
                trace(this,"OSC ready");
            }catch(e:Error){    trace(e.getStackTrace());   }   
        }
        public function acceptOSCPacket(oscPacket:OSCPacket):void{
            //handle OSC here
            var message:OSCMessage = oscPacket as OSCMessage;
            trace("message from :",message.address,"at",new Date());
            for(var i:int = 0; i < message.arguments.length; i++)
                trace("\targs["+i+"]",message.arguments[i]);
        }
    }
}

This is roughly what I used for some of these projects:



来源:https://stackoverflow.com/questions/23202572/adobe-air-desktop-application-communicate-with-processing-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!