예제 #1
0
파일: led8x8.py 프로젝트: rwniessen/msgkit
    def Run(self):
        """ This is the mainline code of the demo app
        """
        try:
            mk = msgkit("app", self.execname, msghandler=self.RecvMessage, access="private")
            print("%s is now running msgkit" % self.execname)

            peeraddr, peerport, peername = mk.getPeerID()
            # print 'PeerID: addr=%s, port=%d, name=%s' % (
            #       peeraddr, peerport, peername)

            appaddr, appport, appname = mk.getAppID()
            print("AppID: addr=%s, port=%d, name=%s" % (appaddr, appport, appname))

            mk.StartServer()
            # find the supporting peer & svc app
            ssvcid = "led8x8"
            lss = mk.LaunchSpecialService(ssvcid)
            print(lss.msg)
            if lss.IsOK() == True:
                print("increment the worm length a couple of times ...")
                mtype, mbody = mk.SendMessage(lss.svcpeerip, lss.svcappport, msgAPPS, "led8x8 start")
                print((mtype, mbody))

                for i in range(0, 4):
                    mtype, mbody = mk.SendMessage(lss.svcpeerip, lss.svcappport, msgAPPS, "led8x8 length inc")
                    print((mtype, mbody))
                    time.sleep(5)
                for i in range(0, 4):
                    mtype, mbody = mk.SendMessage(lss.svcpeerip, lss.svcappport, msgAPPS, "led8x8 length dec")
                    print((mtype, mbody))
                    time.sleep(5)

                if self.exit:
                    mtype, mbody = mk.SendMessage(lss.svcpeerip, lss.svcappport, msgAPPS, QUIT)  # terminate svc
                    print((mtype, mbody))

        except:
            traceback.print_exc()
        finally:
            print("%s is quitting ..." % self.execname)
            mk.StopServer()
예제 #2
0
            peerconn.senddata(ERROR, 'unknown message: %s' % msgdata)

        # ~~~~~~~~~~~ end of LED8x8 class ~~~~~~~~~~~~~




# setup and run r-app
if __name__=='__main__':

    os.chdir(sys.path[0]) # set the current working directory
    svcname = os.path.basename(sys.argv[0])
    remapp = LED8x8(svcname, 0.5, 1)
    try:
        mk = msgkit('app', svcname, 
                     msghandler=remapp.HandleAppMessages,
                     access='public')
        print('%s is now running msgkit' % svcname)
        '''
        peeraddr, peerport, peername = mk.getPeerID()
        print 'PeerID: addr=%s, port=%d, name=%s' % (
               peeraddr, peerport, peername)            
        appaddr, appport, appname = mk.getAppID()
        print 'AppID: addr=%s, port=%d, name=%s' % (appaddr, appport, appname)
        '''
        mk.StartServer()
        print('%s is ready to roll ...' % svcname)

        while remapp.worm.bRun == True:
            #print remapp.msgq.get(False, None)
            time.sleep(1)