示例#1
0
 def request(self, server, device, message, args={}) :
     if server in self.servers :
         r = self.servers[server].request(device, message, args)
         dest = (self.servers[server].host, self.servers[server].port)
         self.sock.sendto(sexp.write(r), dest)
         print "sent "+sexp.write(r)
     else :
         raise Exception("No such server to request: "+server)
示例#2
0
 def run(self) :
     print "Starting broadcast server."
     self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     self.s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
     self.s.bind(("", s.SQUIDNET_BROADCAST_PORT))
     self.s.settimeout(5)
     while self.go :
         try :
             message, address = self.s.recvfrom(4096 << 10)
             print "Got data from", address
             # Acknowledge it.
             xs = sexp.read_all(message)
             for x in xs :
                 if x == sexp.Symbol("info") :
                     print "Giving info"
                     self.s.sendto(sexp.write(self.server_info.get_sexp()), address)
                 else :
                     print "Ignoring"
         except socket.error :
             pass # just a timeout
         except :
             traceback.print_exc()
     self.s.close()
示例#3
0
文件: views.py 项目: axiak/tep-lights
def send_request(serverinfo, device, message, args):
    r = serverinfo.info.request(device, message, args)
    dest = serverinfo.info.host, serverinfo.info.port
    sockdata.sock.sendto(sexp.write(r), dest)
示例#4
0
                print "Pinging",l[1]
                info.ping(l[1])
                #info.ping(l[1])
            elif l[0] == "servers" :
                for serv in info.servers.keys() :
                    print serv
            elif l[0] == "devices" :
                for d in info.servers[l[1]].devices :
                    print "%s\t%s" % (d.name, d.desc)
            elif l[0] == "messages" :
                for m in info.servers[l[1]].get_device(l[2]).messages :
                    print "%s %s - %s" % (m.name,
                                         ''.join("(%s, %s)" % (a.name, a.argtype.clssquidtype()) for a in m.arguments),
                                        m.desc)
            elif l[0] == "request" :
                c = i.split(" ", 4)
                if len(c) < 5 :
                    c.append("")
                m = info.servers[c[1]].get_device(c[2]).get_message(c[3])
                args = m.decode_sexp_args(sexp.read_all(c[4]))
                info.request(c[1], c[2], c[3], args)
            elif l[0] == "dump" :
                print sexp.write(info.servers[l[1]].get_sexp())
            elif l[0] in ('quit', 'exit'):
                break
        except (KeyboardInterrupt, EOFError) :
            break
        except :
            traceback.print_exc()
            pass
示例#5
0
 def _set_info(self, info):
     self.pickled_data = sexp.write(info.get_sexp())
     self._info = info