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


Python PandaModules.QueuedConnectionReader类代码示例

本文整理汇总了Python中pandac.PandaModules.QueuedConnectionReader的典型用法代码示例。如果您正苦于以下问题:Python QueuedConnectionReader类的具体用法?Python QueuedConnectionReader怎么用?Python QueuedConnectionReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Client

class Client(DirectObject):
    def __init__(self):
        self.cManager = QueuedConnectionManager()
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager,0)
        self.connection = None #Connection with the server
        
    def connectToServer(self, ip_address="192.168.1.110", port_address=9099):
        #How long to wait until we give up connecting
        timeout = 3000 # 3 seconds
        self.connection = self.cManager.openTCPClientConnection(ip_address,port_address,timeout)
        if self.connection:
            self.cReader.addConnection(self.connection) #Retrieve message from Server
            return True #We connected
        return False #We couldn't succeed
    
    def processMsgData(self, dataGram):
        iterator = PyDatagramIterator(dataGram)
        msgID = iterator.getUint8()
        if msgID == PRINT_MESSAGE:
            msg = iterator.getString()
            print msg
    
    def recieveMessage(self):
        datagram = NetDatagram() #Needed to store the message or data recieved
        if self.cReader.getData(datagram):
            self.processMsgData(datagram)
            
    
    '''
    Closes the connection with the server
    '''
    def disconnectServer(self):
        self.cManager.closeConnection(self.connection)
开发者ID:muadibbm,项目名称:COMP361Project,代码行数:34,代码来源:server_and_client.py

示例2: Client

class Client():
    
    def __init__(self):
        self.cManager = QueuedConnectionManager()
        self.tcpWriter = ConnectionWriter(self.cManager,0)
        self.tcpReader = QueuedConnectionReader(self.cManager, 0)
        taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
        
        # This fails
        self.conn = self.cManager.openTCPClientConnection(IP_ADDR, PORT, 1000)
        if self.conn:
            print 'Successful connection to', IP_ADDR, ':', PORT
            self.tcpReader.addConnection(self.conn)
            
            self.SendPacket()
            
    def SendPacket(self):
        dg = PyDatagram()
        dg.addUint8(5)
        self.tcpWriter.send(dg, self.conn)
            
    def tskReaderPolling(self, task):
        if self.tcpReader.dataAvailable():
            datagram = NetDatagram()
            if self.tcpReader.getData(datagram):
                print 'client got data'
        return task.cont
开发者ID:czorn,项目名称:Modifire,代码行数:27,代码来源:TestTCP.py

示例3: Client

class Client(DirectObject): 
    def __init__( self ): 
        print "Initializing client test" 
        
        self.port = 9099
        self.ip_address = "142.157.150.72" 
        self.timeout = 3000             # 3 seconds to timeout 
        
        self.cManager = QueuedConnectionManager() 
        self.cListener = QueuedConnectionListener(self.cManager, 0) 
        self.cReader = QueuedConnectionReader(self.cManager, 0) 
        self.cWriter = ConnectionWriter(self.cManager,0) 
        
        self.Connection = self.cManager.openTCPClientConnection(self.ip_address, self.port, self.timeout) 
        if self.Connection: 
            taskMgr.add(self.tskReaderPolling,"read the connection listener",-40) 
            # this tells the client to listen for datagrams sent by the server 
            
            print "Connected to Server" 
            self.cReader.addConnection(self.Connection) 
            PRINT_MESSAGE = 1 
            myPyDatagram = PyDatagram() 
            myPyDatagram.addUint8(100) 
            # adds an unsigned integer to your datagram 
            myPyDatagram.addString("first string of text") 
            # adds a string to your datagram 
            myPyDatagram.addString("second string of text") 
            # adds a second string to your datagram 
            self.cWriter.send(myPyDatagram, self.Connection) 
            # fires it off to the server 
            
            #self.cManager.closeConnection(self.Connection) 
            #print "Disconnected from Server" 
            # uncomment the above 2 lines if you want the client to 
            # automatically disconnect.  Or you can just 
            # hit CTRL-C twice when it's running to kill it 
            # in windows, I don't know how to kill it in linux 
        else: 
            print "Not connected to Server" 
        
    def tskReaderPolling(self, task): 
        if self.cReader.dataAvailable(): 
            datagram=PyDatagram()  
            if self.cReader.getData(datagram): 
                self.processServerMessage(datagram) 
        return Task.cont        
    
    def processServerMessage(self, netDatagram): 
        myIterator = PyDatagramIterator(netDatagram) 
        print myIterator.getString() 
开发者ID:muadibbm,项目名称:COMP361Project,代码行数:50,代码来源:client_test2.py

示例4: CreateTCPConnection

 def CreateTCPConnection(self):
     self.tcpSocket = self.cManager.openTCPServerRendezvous(Globals.PORT_SERVER_LISTENER, 1000)
     self.tcpWriter = ConnectionWriter(self.cManager,0)
     self.tcpListener = QueuedConnectionListener(self.cManager, 0)
     self.tcpListener.addConnection(self.tcpSocket)
     self.tcpReader = QueuedConnectionReader(self.cManager, 0)
     return True
开发者ID:czorn,项目名称:Modifire,代码行数:7,代码来源:Server.py

示例5: __init__

	def __init__(self, port, backlog = 1000, compress = False):
		ShowBase.__init__(self)

		self.compress = compress

		self.cManager = QueuedConnectionManager()
		self.cListener = QueuedConnectionListener(self.cManager, 0)
		self.cReader = QueuedConnectionReader(self.cManager, 0)
		self.cWriter = ConnectionWriter(self.cManager,0)
		
		self.clientdb = ClientDataBase()
		if not self.clientdb.connected:
			self.clientdb = None
			print 'Login Server failed to start...'
		else:
			# This is for pre-login
			self.tempConnections = []
			
			# This is for authed clients
			self.activeClients = []
			# This is for authed servers
			self.activeServers = []
			# This is for authed chat servers
			self.activeChats = []
			
			self.connect(port, backlog)
			self.startPolling()
			
			self.taskMgr.doMethodLater(0.5, self.lobbyLoop, 'Lobby Loop')
			
			print 'Login Server operating...'
开发者ID:H3LLB0Y,项目名称:Centipede,代码行数:31,代码来源:loginserver.py

示例6: __init__

	def __init__(self):
		''' Initialize the server.'''
		
		import __builtin__
		__builtin__.LOG = LogConsole()
		
		print('Starting PSG Server ...')
		self._cManager  = QueuedConnectionManager()
		self._cListener = QueuedConnectionListener(self._cManager, 0)
		self._cReader   = QueuedConnectionReader(self._cManager, 0)
		self._cWriter   = ConnectionWriter(self._cManager,0)
		
		#TODO - Load user file (DB)
		self.registeredUsers =[ServerPlayer('chad','password1'),
							   ServerPlayer('josh','password2'),
							   ServerPlayer('james','password3')]
		
		# Map store
		self._mapStore = MapStore()
		
		# Open socket
		self._tcpSocket = self._cManager.openTCPServerRendezvous(PORT,BACKLOG)
		self._cListener.addConnection(self._tcpSocket)
		
		# Setup interfaces
		self._console = InterfaceConsole(self)
		
		# Setup system tasks
		taskMgr.add(self.__listenTask, 'serverListenTask', -40)
		taskMgr.add(self.__readTask, 'serverReadTask', -39)
		taskMgr.doMethodLater(PING_DELAY, self.__pingTask, 'serverPingTask', sort=-41)
		taskMgr.doMethodLater(1, self.__checkPingRespTask, 'serverCheckPingRespTask', sort=-10)
		
		print('Server initialized')
开发者ID:crempp,项目名称:psg,代码行数:34,代码来源:GameServer.py

示例7: __init__

    def __init__(self, port='9099', timeout=3.0, commTicks=50, resendTime=0.33, reliable=0, concurrent=10, maxlength=480):
        self.logger = logging.getLogger('UDPcon')
        self.port = port
        # Start the UDP Connection
        self.cManager = QueuedConnectionManager()
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)
        self.conn = self.cManager.openUDPConnection(self.port)
        self.cReader.addConnection(self.conn)
        self.handlers = {}
        self.nextID = 1
        self.commBuffer = []
        self.conAddresses = []
        self.conIDs = []
        self.timeout = timeout
        self.commTicks = commTicks
        self.commTime = 1.0 / self.commTicks
        self.time = ClockObject()
        self.resendTime = resendTime
        self.reliable = reliable
        self.concurrent = concurrent
        self.maxlength = maxlength
        self.multMsgID = 0
        # receive data
        taskMgr.add(self.listendata, "Incoming Data Listener", -40)
        # send the data in the send buffer
        taskMgr.doMethodLater(self.commTime, self.batch, "Batch")
        self.handlers[KEEP_ALIVE] = self.reply
        self.handlers[CONFIRM] = self.sync
#        logging.debug('UDPconnection created')
        self.logger.debug('UDPconnection created')
开发者ID:lgo33,项目名称:NetPanda,代码行数:31,代码来源:UDPconnection.py

示例8: __init__

 def __init__(self):
     self.cManager = QueuedConnectionManager()
     self.tcpSocket = self.cManager.openTCPServerRendezvous(PORT, 1000)
     self.tcpWriter = ConnectionWriter(self.cManager,0)
     self.tcpListener = QueuedConnectionListener(self.cManager, 0)
     self.tcpListener.addConnection(self.tcpSocket)
     self.tcpReader = QueuedConnectionReader(self.cManager, 0)
     
     taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
     taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
开发者ID:czorn,项目名称:Modifire,代码行数:10,代码来源:TestTCP.py

示例9: Server

class Server():
    
    def __init__(self):
        self.cManager = QueuedConnectionManager()
        self.tcpSocket = self.cManager.openTCPServerRendezvous(PORT, 1000)
        self.tcpWriter = ConnectionWriter(self.cManager,0)
        self.tcpListener = QueuedConnectionListener(self.cManager, 0)
        self.tcpListener.addConnection(self.tcpSocket)
        self.tcpReader = QueuedConnectionReader(self.cManager, 0)
        
        taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
        taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
        
    def SendPacket(self):
        dg = PyDatagram()
        dg.addUint8(5)
        self.tcpWriter.send(dg, self.conn)
        
    def tskReaderPolling(self, task):
        if self.tcpReader.dataAvailable():
            datagram = NetDatagram()
            if self.tcpReader.getData(datagram):
                print 'server got data'
                self.SendPacket()
        return task.cont
    
    def tskListenerPolling(self, task):
        if self.tcpListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            netAddress = NetAddress()
            newConnection = PointerToConnection()
        
            if self.tcpListener.getNewConnection(rendezvous, netAddress, newConnection):
                newConnection = newConnection.p()
                self.tcpReader.addConnection(newConnection)
                self.conn = newConnection
                print self.conn.getAddress().getPort()
        return task.cont
开发者ID:czorn,项目名称:Modifire,代码行数:38,代码来源:TestTCP.py

示例10: __init__

 def __init__(self, port, backlog=1000, compress=False):
     self.port = port
     self.backlog = backlog
     self.compress = compress
     
     self.cManager = QueuedConnectionManager()
     self.cListener = QueuedConnectionListener(self.cManager, 0)
     self.cReader = QueuedConnectionReader(self.cManager, 0)
     self.cWriter = ConnectionWriter(self.cManager,0)
     
     self.activeConnections = [] # We'll want to keep track of these later
     
     self.connect(self.port, self.backlog)
     self.startPolling()
开发者ID:gelatindesign,项目名称:Colony,代码行数:14,代码来源:Server.py

示例11: __init__

    def __init__(self):
        self.cManager = QueuedConnectionManager()
        self.cListener = QueuedConnectionListener(self.cManager, 0)
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager,0)
 
        self.activeConnections = [] # Keeps tracks of active connections
        
        #Set up the connection
        port_address=9099 #No-other TCP/IP services are using this port
        backlog=1000 #If we ignore 1,000 connection attempts, something is wrong!
        self.tcpSocket = self.cManager.openTCPServerRendezvous(port_address,backlog)
 
        self.cListener.addConnection(self.tcpSocket)
        self.setTaskManagers() #Set the Managers
开发者ID:muadibbm,项目名称:COMP361Project,代码行数:15,代码来源:server_and_client.py

示例12: __init__

    def __init__(self, host, port, timeout=3000, compress=False):
        self.host = host
        self.port = port
        self.timeout = timeout
        self.compress = compress

        self.cManager = QueuedConnectionManager()
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)

        # By default, we are not connected
        self.connected = False

        self.connect(self.host, self.port, self.timeout)
        self.startPolling()
开发者ID:H3LLB0Y,项目名称:Warlocks,代码行数:15,代码来源:client.py

示例13: StartConnectionManager

 def StartConnectionManager(self): 
     # this function creates a connection manager, and then 
     # creates a bunch of tasks to handle connections 
     # that connect to the server 
     self.cManager = QueuedConnectionManager() 
     self.cListener = QueuedConnectionListener(self.cManager, 0) 
     self.cReader = QueuedConnectionReader(self.cManager, 0) 
     self.cWriter = ConnectionWriter(self.cManager,0) 
     self.tcpSocket = self.cManager.openTCPServerRendezvous(self.port,self.backlog)
     self.cListener.addConnection(self.tcpSocket) 
     self.portStatus = "Open" 
     taskMgr.add(self.ConnectionManagerTASK_Listen_For_Connections,"Listening for Connections",-39) 
     # This task listens for new connections 
     taskMgr.add(self.ConnectionManagerTASK_Listen_For_Datagrams,"Listening for Datagrams",-40) 
     # This task listens for new datagrams 
     taskMgr.add(self.ConnectionManagerTASK_Check_For_Dropped_Connections,"Listening for Disconnections",-41) 
开发者ID:muadibbm,项目名称:COMP361Project,代码行数:16,代码来源:server_example.py

示例14: CreateUDPConnection

 def CreateUDPConnection(self):   
     self.cManager = QueuedConnectionManager()
     self.cReader = QueuedConnectionReader(self.cManager, 0)
     self.cWriter = ConnectionWriter(self.cManager,0)
     self.conn = self.cManager.openUDPConnection(Globals.PORT_SERVER_LISTENER)
     
     if(self.conn):
         self.log.WriteLine('Connection on %s okay.' % (Globals.PORT_SERVER_LISTENER))
     else:
         self.log.WriteError('Connection on %s failed.' % (Globals.PORT_SERVER_LISTENER))
         sys.exit()
         return False
 
     self.cReader.addConnection(self.conn)
     
     return True
开发者ID:czorn,项目名称:Modifire,代码行数:16,代码来源:Server.py

示例15: __init__

    def __init__(self, port, virtual_world, camera_mgr, sync_session):
        self.port = port
        self.virtual_world = virtual_world
        self.cam_mgr = camera_mgr
        
        self.task_mgr = virtual_world.taskMgr
        self.cManager = QueuedConnectionManager()
        self.cListener = QueuedConnectionListener(self.cManager, 0)
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cReader.setRawMode(True)
        self.cWriter = ConnectionWriter(self.cManager, 1)
        self.cWriter.setRawMode(True)
        self.tcpSocket = self.cManager.openTCPServerRendezvous(port, BACKLOG)
        self.cListener.addConnection(self.tcpSocket)
        
        self.activeSessions = {}
        self.connection_map = {}
        self.set_handlers()
        
        hostname = socket.gethostname()
        a, b, address_list = socket.gethostbyname_ex(hostname)
        self.ip = address_list[0]
        logging.info("Addresses %s" % address_list)
        logging.info("Server is running on ip: %s, port: %s" 
                     %(self.ip, self.port))
        
        self.client_counter = 0
        self.read_buffer = ''
        self.read_state = 0
        self.read_body_length = 0
        self.packet = SocketPacket()
        
        controller = virtual_world.getController()
        self.sync = Sync(self.task_mgr, controller, camera_mgr, sync_session)
        self.vv_id = None
        if sync_session:
            logging.info("Waiting for Sync Client!")
        
        self.showing_info = False
        virtual_world.accept("i", self.toggleInfo)
        self.sync_session = sync_session
        self.createInfoLabel()

        atexit.register(self.exit)
开发者ID:shubhamgoyal,项目名称:virtual-vision-simulator,代码行数:44,代码来源:socket_server.py


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