当前位置: 首页>>代码示例>>Python>>正文


Python Factory.clients方法代码示例

本文整理汇总了Python中twisted.internet.protocol.Factory.clients方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.clients方法的具体用法?Python Factory.clients怎么用?Python Factory.clients使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.protocol.Factory的用法示例。


在下文中一共展示了Factory.clients方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
 def run(self):
     global factory
     factory = Factory()
     factory.clients = []
     factory.protocol = LightServer
     reactor.listenTCP(7002, factory)
     global connections
     connections = []
     reactor.run(installSignalHandlers=False)
开发者ID:hoedding,项目名称:Studienarbeit-Anwendung,代码行数:11,代码来源:Server.py

示例2: button1Click

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
  def button1Click(self):  
    #print "button1Click event handler" 
    self.button1["background"] = "yellow"
    import select
    import sys
    import pybonjour

    name    = 'gamepanel'
    regtype = '_gamepanel._tcp'
    port    = 3333
##name    = sys.argv[1]
##regtype = sys.argv[2]
####port    = int(sys.argv[3])


    def register_callback(sdRef, flags, errorCode, name, regtype, domain):
        if errorCode == pybonjour.kDNSServiceErr_NoError:
            print 'Registered service:'
            print '  name    =', name
            print '  regtype =', regtype
            print '  domain  =', domain
    sdRef = pybonjour.DNSServiceRegister(name = name,
                                   regtype = regtype,
                                   port = port,
                                   callBack = register_callback)


    class IphoneChat(Protocol):
        def connectionMade(self):
            self.factory.clients.append(self)
            #print "clients are ", self.factory.clients

        def connectionLost(self, reason):
            self.factory.clients.remove(self)

        def dataReceived(self, data):
          a = data
          #print a
          if a == data:
#             import SendKeys
             SendKeys.SendKeys(a)         
             time.sleep(1)
#             reactor.run(installSignallHandlers=True)

        def message(self, message):
           self.transport.write(message)
    
    factory = Factory()
    factory.protocol = IphoneChat
    factory.clients = []
    reactor.listenTCP(3333, factory)
  
    
    
    
        
    self.button1["background"] = "green"
开发者ID:funkboy27,项目名称:GamePanelServer,代码行数:59,代码来源:gamepanelmain.py

示例3: main

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
def main():
    server = Server()
    f = Factory()
    # f.client_host = 
    f.protocol = WebClient
    f.clients = []
    f.server = server

    reactor.listenTCP(8080, f)
    print 'Listening on port', 8080
    reactor.run()
开发者ID:renatopp,项目名称:dojo2py,代码行数:13,代码来源:server.py

示例4: main

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
def main():
    # Run ROS node
    rospy.init_node('tablet_server')

    # Start the server/reactor loop
    factory = Factory()
    factory.protocol = RobotComm
    factory.clients = []
    reactor.listenTCP(11411, factory)
    reactor.run()

    rospy.spin()
开发者ID:OSUrobotics,项目名称:turtlebot_teamwork,代码行数:14,代码来源:tablet_server_node.py

示例5: main

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
def main(args):
    global node
    arg = parse_arguments(args)
    port = arg.udp_port
    if arg.known_ip and arg.known_port:
        known_nodes = [(arg.known_ip, int(arg.known_port))]
    elif arg.config_file:
        known_nodes = []
        f = open(arg.config_file, 'r')
        lines = f.readlines()
        f.close()
        for line in lines:
            ip_address, udp_port = line.split()
            known_nodes.append((ip_address, int(udp_port)))
    else:
        known_nodes = None

    # Set up SQLite-based data store
    if os.path.isfile('/tmp/dbFile%s.db' % sys.argv[1]):
        os.remove('/tmp/dbFile%s.db' % sys.argv[1])
    data_store = SQLiteDataStore(dbFile = '/tmp/db_file_dht%s.db' % port)

    # Generate the Key from the peer profile
    r = requests.get('http://localhost:5000/api/profile')
    val = cStringIO.StringIO(str(r.text))
    pear_profile = numpy.loadtxt(val)
    KEY = str(lsh(pear_profile))
    # Bit of a hack. But this return the IP correctly. Just gethostname
    # sometimes returns 127.0.0.1
    # VALUE =  ([l for l in ([ip for ip in
        # socket.gethostbyname_ex(socket.gethostname())[2] if not
        # ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)),
            # s.getsockname()[0], s.close()) for s in
            # [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]])
        # if l][0][0])
    # The real setup should use the following to get external IP. I am
    # using the one above since I use docker
    VALUE = urllib.urlopen('http://ip.42.pl/short').read().strip('\n')

    factory = Factory()
    factory.protocol = PeARSearch
    factory.clients = []
    node = EntangledNode(udpPort=int(port), dataStore=data_store)
    node.joinNetwork(known_nodes)
    reactor.callLater(0, storeValue, KEY, VALUE, node)
    reactor.listenTCP(8080, factory)
    print "Starting the DHT node..."
    reactor.addSystemEventTrigger('before','shutdown', cleanup, KEY,
            node)
    reactor.run()
开发者ID:PeARSearch,项目名称:p2p-network,代码行数:52,代码来源:dht.py

示例6: twistedServer

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
def twistedServer():
    def RaspberryLight(Protocol):
	def connectionMade(self):
		#self.transport.write("""connected""")
		self.factory.clients.append(self)
		print "clients are ", self.factory.clients

	def connectionLost(self, reason):
		print "connection lost ", self.factory.clients
		self.factory.clients.remove(self)


	def dataReceived(self, data):
                        global reset
			msg = ""

##			if (data == 'P7H'):
##				msg = "Pin 7 is now High"
##				GPIO.output(7, True)
##
##			elif (data == 'P7L'):
##				msg = "Pin 7 is now Low"
##				GPIO.output(7, False)

			if (data == 'test'):
                            msg = "YAY THE PHONE SENT A MESSAGE as;dfjasl;ldjflkasdjfasjdflsajflksajdlfjasdkfjas;l"
                        elif (data == 'reset door'):
                            reset = True
                            print "reset door"


			print msg

    factory = Factory()
    factory.protocol = RaspberryLight
    factory.clients = []
    reactor.listenTCP(7777, factory)
    print "RaspberryLight server started"
    reactor.run()
开发者ID:DakotaHarward,项目名称:Darwin,代码行数:41,代码来源:main1.py

示例7: startService

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
def startService(textbuffer, port, welcome, statusbar):
    addText(textbuffer, APP_NAME, LOG_INFO)
    addText(textbuffer, _("Version ") + APP_VERSION, LOG_INFO)
    addText(textbuffer, _("Attempting to start server at port ") + str(port) + "\n", LOG_INFO)
    addText(textbuffer, _("Creating Factory"), LOG_INFO)

    factory = Factory()
    factory.protocol = RPG
    factory.textbuffer = textbuffer
    factory.statusbar = statusbar
    factory.clients = []

    addText(textbuffer, _("Saving welcome message..."), LOG_INFO)
    factory.welcome = welcome
    f = open(PATH_WELCOME_MSG, "w")
    f.write(welcome)
    f.close()
    addText(textbuffer, _("Setting up Users datastructure"), LOG_INFO)
    factory.users = Users()
    addText(textbuffer, _("Listening for incoming connections..."), LOG_INFO)
    reactor.listenTCP(port, factory)
    reactor.run()
开发者ID:rhcarvalho,项目名称:SimplePythonChatter,代码行数:24,代码来源:serverProtocol.py

示例8: dataReceived

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
        self.factory.clients.remove(self)
        
    def dataReceived(self, data):
        a = data.split(':')
        print a
        
        if len(a) > 1:
            command = a[0]
            content = a[1]
 
            msg = ""
            if command == "iam":
                self.name = content
                msg = self.name + " has joined"
 
            elif command == "msg":
                msg = self.name + ": " + content
                print msg
 
            for c in self.factory.clients:
                c.message(msg)
                
    def message(self, message):
    	self.transport.write(message + '\n')
 
factory = Factory()
factory.protocol = IphoneChat
factory.clients = []
reactor.listenTCP(880, factory)
print "Iphone Chat server started"
reactor.run()
开发者ID:deltac2008,项目名称:fuzzypixels,代码行数:33,代码来源:ichatserver.py

示例9: hostIPaddress

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
		for fclient in self.factory.clients:
		    if fclient.transport.getPeer().host == spl[1]:
			fclient.transport.write(msg+"^")
			return

def hostIPaddress():      
    try:
	s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	s.connect(("gmail.com",80))
	myhostip = s.getsockname()[0]
	s.close()
	return myhostip
    except:
	print "Internet disconnected?"
	return 0

if __name__ == "__main__":
    myhostip = hostIPaddress()
    if not myhostip:
	sys.exit()
    factory = Factory()
    factory.protocol = Server
    factory.clients = [] # clients list
    factory.host = None

    PORT = 50000 # port of the server
    reactor.listenTCP(PORT, factory)
    print "[ Server info ]\nServer IP : %s\nPort : %d" %(myhostip, PORT)
    print "Server is now running.\nPress [ Ctrl-c ] to close the server."
    reactor.run()
开发者ID:omega3love,项目名称:BridgeProject,代码行数:32,代码来源:bridgeServer.py

示例10: dataReceived

# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import clients [as 别名]
        logging.info("Connection lost")
        self.factory.clients.remove(self)
        self.factory.ips.remove(self.ip)

    def dataReceived(self, data):
        logging.debug("Spreading "+str(len(data))+" bytes to "+str(len(self.factory.clients))+" clients")
        for p in self.factory.clients:
            if p != self:
                p.transport.write(data)


clients = []
ips = []

f_tcp = Factory()
f_tcp.protocol = Client
f_tcp.clients = clients
f_tcp.ips = ips


from twisted.python import log
observer = log.PythonLoggingObserver()
observer.start()

from twisted.application import internet, service
from twisted.internet import reactor
application = service.Application("orpend")  # create the Application
tcpService = internet.TCPServer(24142, f_tcp) # create the service
tcpService.setServiceParent(application)

开发者ID:shish,项目名称:orpen,代码行数:31,代码来源:server.py


注:本文中的twisted.internet.protocol.Factory.clients方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。