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


Python network.poll函数代码示例

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


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

示例1: send_network

    def send_network(self, cmd):
        self.cmds = ['up', 'down', 'left', 'right']
        poll()
        if cmd in self.cmds:

            msg = cmd
            self.do_send({'input' : msg})
开发者ID:jeffs5,项目名称:INFX123,代码行数:7,代码来源:bot.py

示例2: poll

    def poll(self):

        poll()

        p = self.m.pellets[0]  # always target the first pellet
        b = self.m.mybox
        if p[0] > b[0]:
            cmd = 'right'
        elif p[0] < b[0]: # p[2] to avoid stuttering left-right movement
            cmd = 'left'
        elif p[1] > b[1]:
            cmd = 'down'
        else:
            cmd = 'up'
        self.m.do_cmd(cmd)
开发者ID:ronnienv,项目名称:INF123-Assignments,代码行数:15,代码来源:bot.py

示例3: poll

 def poll(self):
    poll() 
    if len(self.m.players) > 0:
       p = self.m.pellets[0]  # always target the first pellet
       b = self.m.mybox
       if p[0] > b[0]:
           cmd = 'right'
       elif p[0] + p[2] < b[0]: # p[2] to avoid stuttering left-right movement
           cmd = 'left'
       elif p[1] > b[1]:
           cmd = 'down'
       else:
           cmd = 'up'
       msg = {'input': cmd}
       self.m.do_send(msg)
开发者ID:dhumes,项目名称:Informatics123,代码行数:15,代码来源:bot.py

示例4: run

def run():

    #while 1:
    
        # enqueue the player events received by the client handlers
        poll()
        
        '''checks what kind of event happened, then filters it so that it can send the correct
        event out to the clients.
    
        within the messages, the first part is the type of message(player joined, player quit
            player pushed a key, etc)
        the second part is the name of the player that did that event
        '''
        '''
        for event, handler in event_queue:
            if event == 'quit':
                msg = {'msg_type':'quit',
                       'their_name': players[handler].name(),
                       }
                del players[handler]
                broadcast(msg)
                
            elif event == 'join':
                player_name = generate_name()
                players[handler] = Player(player_name)
                msg = {'msg_type': 'join',
                       'their_name': players[handler].name(),
                       'players_list': players
                       }
                broadcast(msg)
            
            elif event == 'input':
                msg = {'msg_type': 'player_movement',
                         'their_name': players[handler].name(),
                         'input': event
                         }
                broadcast(msg)
        
            elif event == 'shot':
                msg = {'msg_type': 'player_shot',
                       'their_name': players[handler].name()
                      }
                broadcast(msg)
        '''
        event_queue = []
    
        sleep(1. / 20) # seconds
开发者ID:rafasimao,项目名称:SpaceInvadersCS,代码行数:48,代码来源:server.py

示例5: run

def run():
    #while 1:
        
        #msg = "" #message
        #if msg == 'quit' or msg == 'exit':
        #    client.do_close()
        #elif msg: # ignore empty strings
        #client.do_send({'myname': myname, 'input': msg})
            
        poll() # push and pull network messages

        #for m in event_queue:
        #process_input("")#m) 
        event_queue = []
        
        sleep(1. / 20) # seconds
开发者ID:rafasimao,项目名称:SpaceInvadersCS,代码行数:16,代码来源:client.py

示例6: poll

 def poll(self):
    poll() 
    if len(self.m.players) != 0:
       p = self.m.pellets[0]  # always target the first pellet
       b = self.m.players[self.m.players.keys()[0]]      
       if p[0] > b[0]:
           cmd = 'right'
           # print p
       elif p[0] + p[2] < b[0]:
           cmd = 'left'
       elif p[1] > b[1]:
           cmd = 'down'
           # print p
       elif p[1] == b[1]:
           cmd = 'left'
       elif p[0] == b[0]:
           cmd = 'right'
       else:
           cmd = 'up'
         
       msg = {'input': cmd}
       self.m.do_send(msg)
开发者ID:ronvenna,项目名称:INF123,代码行数:22,代码来源:bot.py

示例7: periodic_poll

def periodic_poll():
    while 1:
        if not len(chatting) and len(connected_users):
            next_user = connected_users.values()[0]
            chatting[next_user.handler] = next_user
            print "user in room"
            
        elif len(chatting) == 1 and chatting.keys()[0] in connected_users and len(connected_agents):
            next_agent = connected_agents.values()[0]
            for person in chatting:
                    person.do_send({'join': next_agent.name})
            next_agent.handler.do_send({'speak': chatting.values()[0].name.upper(), 'txt': chatting.values()[0].topic.upper()})
            chatting[next_agent.handler] = next_agent
            print "agent joins user"
            
        elif len(chatting) == 1 and chatting.keys()[0] in connected_agents and len(connected_users):
            next_user = connected_users.values()[0]
            for person in chatting:
                    person.do_send({'join': next_user.name})
            chatting.keys()[0].do_send({'speak': next_user.name.upper(), 'txt': next_user.topic.upper()})
            chatting[next_user.handler] = next_user
            print "user joins agent"
        
        poll(timeout=0.05) # in seconds
开发者ID:heathsias,项目名称:Chat_Agent,代码行数:24,代码来源:server.py

示例8: Client

client = Client('localhost', 8888)

pygame_init()
screen = set_mode((400, 300))
clock = Clock()
font = Font(None, 15)  # default pygame Font, height in pixels

borders = [Rect(0, 0, 2, 300), Rect(0, 0, 400, 2),
           Rect(398, 0, 2, 300), Rect(0, 298, 400, 2)]
dx, dy = 0, 1  # start direction: down
delay = 0  # start moving right away 

while True:
    
    clock.tick(50)  # frames per second
    poll()  # push and pull network messages

    for event in pygame_event.get():  # inputs
        if event.type == QUIT:
            exit()
        if event.type == KEYDOWN:
            key = event.key
            if key == K_ESCAPE:
                exit()
            elif key == K_UP:
                dx, dy = 0, -1
            elif key == K_DOWN:
                dx, dy = 0, 1
            elif key == K_LEFT:
                dx, dy = -1, 0
            elif key == K_RIGHT:
开发者ID:JHECKARD,项目名称:swarch,代码行数:31,代码来源:client.py

示例9: connect_to_peers

            # connect to the peers
            others_ip_port = data['others_ip_port']
            connect_to_peers(others_ip_port)
            # create pellets if I'm the only peer, fetch them otherwise
            if others_ip_port: # other peers have pellets data
                fetch_pellets()
            else:
                create_pellets()


#####################################################################

# Establish connection with the directory server.
dir_client = DirectoryClient(DIRECTORY_HOST, 8888)  # async connect
while not dir_client.connected:
    poll(timeout=.1)  # seconds
print 'Connected to the directory server.'

# Send the IP and port I will be listening to.
# Receive in response the list of (IP, port) of peers in the network.
dir_client.do_send({'mtype': 'join_dir', 
                    'ip_port': my_ip_port})
while not dir_client.directory_received:
    poll(timeout=.1)  # seconds
print 'Retrieved a directory of %d peers.' % len(peers)

# Listen to incoming P2P connections from future peers.
p2p_listener = Listener(my_port, Peer)


pygame.init()
开发者ID:chelseealee,项目名称:swarch,代码行数:31,代码来源:peer.py

示例10: MyListener

        print "SERVER ON_ACCEPT"
        print msg
        print self

class MyListener(Listener):
    def on_accept(self, h):
        print "MYLISTENER CLASS ON_ACCEPT"
        print h
        print self

def parseUser(msg):
    #print "MSG: " + msg
    if msg.find('join') != -1:
        strArr = msg.split("'")
        return strArr[3]
    else:
        return "%$$--#"
#------MODEL------
handlers = {}  # map client handler to user name
port = 7577
server = MyListener(port, MyHandler)    

#------CONTROLLER------
try:
    while 1:
        poll(timeout=0.1)
except KeyboardInterrupt:
    print "CLOSING"
    handlers["Admin"].do_send("ADMIN IS CLOSING")
    currentCustomer.do_send("ADMIN IS CLOSING")
开发者ID:atsuzu,项目名称:137_ChatRoom,代码行数:30,代码来源:server.py

示例11: render

    
def render(handler):
    # render game state into a surface. This rendering varies for each player.
    screen = pygame.Surface((WIDTH, HEIGHT))
    screen.fill((0, 0, 64))  # dark blue
    [pygame.draw.rect(screen, (0, 191, 255), b) for b in borders]  # deep sky blue 
    [pygame.draw.rect(screen, (255, 192, 203), p) for p in pellets]  # shrimp
    [pygame.draw.rect(screen, (255, 0, 0), p.box) for h, p in players.items() if h != handler]
    pygame.draw.rect(screen, (0, 191, 255), players[handler].box)
    return screen

   
while 1:
    loop_start = time.time()
    
    # enqueue the player events received by the client handlers
    apply_client_events()
    update_avatars()
    
    # render and send screenshot
    for h in players.keys():
        surface = render(h) 
        msg = pygame.image.tostring(surface, 'RGB') 
        h.do_send(msg)

    # poll until the tick is over
    while time.time() - loop_start < TICK_DURATION:
        poll(TICK_DURATION - (time.time() - loop_start))

开发者ID:chelseealee,项目名称:swarch,代码行数:27,代码来源:server.py

示例12: periodic_poll

def periodic_poll():
    while 1:
        poll()
        sleep(0.05)
开发者ID:sbetts,项目名称:123repo,代码行数:4,代码来源:lunarlanderclient.py

示例13: MyHandler

from network import Listener, Handler, poll


done = False

class MyHandler(Handler):
    
    def on_open(self):
        print 'srv on open'
        
    def on_close(self):
        print 'srv on close'
    
    def on_msg(self, data):
        print 'srv received %s' % str(data)
        msg = {12: 3, 'hello': (1, 2)}
        self.do_send(msg)
        print 'srv sent %s' % str(msg)
        self.close_when_done()
        global done
        done = True
    

port = 8888
server = Listener(port, MyHandler)
while not done:
    poll(timeout=.1)
server.stop()  # cleanup
开发者ID:chelseealee,项目名称:swarch,代码行数:28,代码来源:simpleserver.py

示例14: update

 def update(self):
     poll(0.01)
开发者ID:rafasimao,项目名称:Software-Architectures,代码行数:2,代码来源:client.py

示例15: set

""" 
Directory: Give the list of connected peers when asked for it.
Keep an up-to-date directory by receiving periodic heartbeats from the peers.
""" 

from network import Listener, Handler, poll


peers = set()

class MyHandler(Handler):
    
    def on_close(self):
        peers.remove(self)
        
    def on_msg(self, data):
        mtype = data['mtype']
        if mtype == 'join_dir':
            self.ip_port = data['ip_port']
            self.do_send({'mtype': 'welcome',
                          'others_ip_port': [p.ip_port for p in peers]})
            peers.add(self)
            

Listener(8888, MyHandler)

while 1:
    poll(timeout=.1)  # seconds
开发者ID:chelseealee,项目名称:swarch,代码行数:28,代码来源:directory.py


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