Monday 15 August 2011

Android - Python communication using zeroMQ -



Android - Python communication using zeroMQ -

with zeromq, possible send ('hello' message) android app created commandline running .recv() in python?

i made android app button, 1 time pressed sends "hello" tcp://machine2:5555.

an extract of button listener:

settingsbutton.setonclicklistener(new onclicklistener(){ public void onclick(final view v) { toast toast = toast.maketext(getapplicationcontext(), "playing video", toast.length_short); toast.show(); // insert ssh command ffmpeg here zmq.context ctx = zmq.context(1); socket soc = ctx.socket(zmq.req); soc.connect("tcp://192.168.0.16:5555"); //system.out.print("established"); string msg = "hi"; soc.send(msg.getbytes(),0); } });

the python receiver running in terminal display message received.

import zmq import time import subprocess port = "5555" #first create context zeromq begin communication context = zmq.context() #pair communication socket = context.socket(zmq.rep) #bind ip address , port opened communication socket.bind("tcp://*:%s" % port) print "tcp://192.168.0.16" while true: msg = socket.recv() if msg not none: print msg #run_command(msg)[0] #subprocess.call(["mplayer","/home/kevo/capture003.dv"]) subprocess.call(["time", "mplayer","/home/kevo/desktop/small.mp4"]) time.sleep(1)

but nil shows on terminal far.

android python zeromq distributed

No comments:

Post a Comment