def _oscHandler(self, addr, tags, stuff, source): addrTokens = addr.lstrip('/').split('/') ## list of all receivers if ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower() == "receivers")): ## as good, if not better than a ping self.lastPingTime = time.time() print "got receivers %s"%(stuff[0]) for rcvr in stuff[0].split(','): self.allReceivers[rcvr] = rcvr if(self.subscribedToAll and not self.subscribedReceivers): self.subscribeToAll() ## hijack /LocalNet/Add ! elif ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower() == "add")): ip = getUrlStr(source).split(":")[0] port = int(stuff[0]) print "adding %s:%s to PantallaServer" % (ip, port) self.allClients[(ip,port)] = addrTokens[2] ## hijack a /LocalNet/ListReceivers elif ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower().startswith("listreceiver"))): ip = getUrlStr(source).split(":")[0] port = int(stuff[0]) ## send list of receivers to client msg = OSCMessage() msg.setAddress("/LocalNet/Receivers") msg.append(self.name) print "got a request for receivers from %s:%s"%(ip,port) try: #self.oscClient.connect((ip, port)) self.oscClient.sendto(msg, (ip, port)) #self.oscClient.connect((ip, port)) except OSCClientError: print "no connection to %s:%s, can't send list of receivers"%(ip,port) ## actual message from AEffect Network !! elif (addrTokens[0].lower() == "aeffectlab"): self.messageQ.put((addrTokens[1], addrTokens[2], stuff[0].decode('utf-8'))) self.messageQ.put((addrTokens[1], addrTokens[2], stuff[0].decode('utf-8'))) ## ping if ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower() == "ping")): self.lastPingTime = time.time() # forward to clients for (ip,port) in self.allClients.keys(): try: #self.oscClient.connect((ip, int(port))) self.oscClient.sendto(self.oscPingMessage, (ip, int(port))) #self.oscClient.connect((ip, int(port))) except OSCClientError: print ("no connection to %s:%s, can't send bang"%(ip,port))
def _oscHandler(addr, tags, stuff, source): addrTokens = addr.lstrip('/').split('/') print addrTokens if (addrTokens[0].lower() == "ffqmesms"): ip = getUrlStr(source).split(":")[0] msg = stuff[0].decode('utf-8') print "got %s from %s" % (msg, ip) messageQ.put((5, msg)) elif (addrTokens[0].lower() == "ffqmeping"): ip = getUrlStr(source).split(":")[0] port = stuff[0] print "got ping from %s %s" % (ip, port) clientMap[(ip, int(port))] = time()
def _oscHandler(addr, tags, stuff, source): addrTokens = addr.lstrip('/').split('/') print addrTokens if (addrTokens[0].lower() == "ffqmesms"): ip = getUrlStr(source).split(":")[0] msg = stuff[0].decode('utf-8') print "got %s from %s" % (msg,ip) messageQ.put((5, msg)) elif (addrTokens[0].lower() == "ffqmeping"): ip = getUrlStr(source).split(":")[0] port = stuff[0] print "got ping from %s %s" % (ip,port) clientMap[(ip,int(port))] = time()
def intercepting_handler(addr, tags, data, source): msg_string = "%s [%s] %s" % (addr, tags, str(data)) sys.stdout.write( "OSCServer Got: '%s' from %s\n" % ( msg_string, getUrlStr(source) )) self.testQueue.put(data)
def espaces_callback(path, tags, args, source): msg_string = "" msg_string += "\n\tpath : %s" % path msg_string += "\n\ttags : %s" % tags msg_string += "\n\targs : %s" % args msg_string += "\n\tsource :%s" % str(source) print "OSCServer received: %s\nfrom %s.\n" % (msg_string, getUrlStr(source)) ir_params = { 'duration' : float(args[4]), 'nu' : float(args[5]), 'sampling_rate' : float(args[6]), 'ev_params' : {'space': str(args[1]), 'c':float(args[2]), 'j_max':int(args[3]),'F':list(args[7:])}, } command = espace_client.handle_request(ir_params) # send reply to the client reply_port = int(args[0]) reply_addresse = (source[0], reply_port) msg = OSCMessage("/pd") msg.append(command['saved_audio_path']) server.client.sendto(msg,reply_addresse,timeout=1) print "OSCServer send:\n\t%s\nto %s.\n" %(msg,reply_addresse) return OSCMessage("/")
def printing_handler(addr, tags, data, source): print "---" print "received new osc msg from %s" % getUrlStr(source) print "with addr : %s" % addr print "typetags :%s" % tags print "the actual data is : %s" % data print "---"
def oscSubscribeHandler(addr, tags, args, source): ip = getUrlStr(source).split(":")[0] port = int(args[0]) print "subscribing %s:%s" % (ip, port) myOscSubscribers[(ip, port)] = (ip, port)
def _oscHandler(self, addr, tags, stuff, source): addrTokens = addr.lstrip('/').split('/') ## /LocalNet/{Add,Remove}/Type -> port-number if ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower() == "add")): ip = getUrlStr(source).split(":")[0] port = int(stuff[0]) self.allPrototypes[(ip,port)] = addrTokens[2] if (addrTokens[3].lower() in self.allReceivers): print "adding "+ip+":"+str(port)+" to "+addrTokens[3].lower()+" receivers" self.allReceivers[addrTokens[3].lower()].addSubscriber((ip,port)) ## if adding osc listener need to setup osc master if((addrTokens[3].lower().startswith('osc')) and (not self.oscMasterIp is None) and (not self.oscMasterPort is None)): print ("adding osc master") try: oscSubscribeMessage = OSCMessage() oscSubscribeMessage.setAddress("/LocalNet/Add/"+addrTokens[2]+"/Osc") oscSubscribeMessage.append(str(self.oscServerPort).encode('utf-8'), 'b') self.oscClient.connect((self.oscMasterIp, int(self.oscMasterPort))) self.oscClient.sendto(oscSubscribeMessage, (self.oscMasterIp, int(self.oscMasterPort))) self.oscClient.connect((self.oscMasterIp, int(self.oscMasterPort))) except OSCClientError: print ("no connection to "+self.oscMasterIp+":"+str(self.oscMasterPort)) elif ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower() == "remove")): ip = getUrlStr(source).split(":")[0] port = int(stuff[0]) if (addrTokens[2].lower() in self.allReceivers): print "removing "+ip+":"+str(port)+" from "+addrTokens[2].lower()+" receivers" self.allReceivers[addrTokens[2].lower()].removeSubscriber((ip,port)) ## only remove from list of prototypes when not in any receiver... inSomeSubscriber = False for k in self.allReceivers: inSomeSubscriber |= self.allReceivers[k].hasSubscriber((ip,port)) if ((not inSomeSubscriber) and ((ip,port) in self.allPrototypes)): print("removing "+self.allPrototypes[(ip,port)]+" @ "+ip+":"+str(port) +" from list of prototypes") del self.allPrototypes[(ip,port)] ## /LocalNet/ListReceivers -> port-number elif ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower().startswith("listreceiver"))): ip = getUrlStr(source).split(":")[0] port = int(stuff[0]) ## send list of receivers to client msg = OSCMessage() msg.setAddress("/LocalNet/Receivers") msg.append(",".join(self.allReceivers.keys())) try: self.oscClient.connect((ip, port)) self.oscClient.sendto(msg, (ip, port)) self.oscClient.connect((ip, port)) except OSCClientError: print ("no connection to "+ip+":"+str(port) +", can't send list of receivers") ## /LocalNet/ListReceivers -> port-number elif ((addrTokens[0].lower() == "localnet") and (addrTokens[1].lower().startswith("listprototype"))): ip = getUrlStr(source).split(":")[0] port = int(stuff[0]) ## send list of prototypes to client msg = OSCMessage() msg.setAddress("/LocalNet/Prototypes") msg.append(",".join(self.allPrototypes.values())) try: self.oscClient.connect((ip, port)) self.oscClient.sendto(msg, (ip, port)) self.oscClient.connect((ip, port)) except OSCClientError: print ("no connection to "+ip+":"+str(port) +", can't send list of prototypes") ## /AEffectLab/{local}/{type} -> msg elif (addrTokens[0].lower() == "aeffectlab"): oscTxt = stuff[0].decode('utf-8') print "forwarding "+addr+" : "+oscTxt+" to my osc subscribers" ## send to all subscribers addr = "/AEffectLab/"+addrTokens[1]+"/"+addrTokens[2] self.sendToAllSubscribers(oscTxt, addr)
def intercepting_handler(addr, tags, data, source): msg_string = "%s [%s] %s" % (addr, tags, str(data)) sys.stdout.write("OSCServer Got: '%s' from %s\n" % (msg_string, getUrlStr(source))) self.testQueue.put(data)
def oscSubscribeHandler(addr, tags, args, source): ip = getUrlStr(source).split(":")[0] port = int(args[0]) print "subscribing %s:%s" % (ip,port) myOscSubscribers[(ip,port)] = (ip,port)