• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python network.poll函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: poll

 def poll(self):
     poll(0.05)
     self.do_send({'input':self.move()})
开发者ID:rafasimao,项目名称:Software-Architectures,代码行数:3,代码来源:bot.py


示例17: poll_messages

 def poll_messages(self):
     poll()
     sleep(.02)
开发者ID:ronnienv,项目名称:WerewolfTag,代码行数:3,代码来源:client.py


示例18: loop

 def loop(self):
     port = 8888
     s = Listener(port, MyHandler)
     while 1:
         poll(timeout=0.05) # in seconds
开发者ID:chelseealee,项目名称:123singlegame,代码行数:5,代码来源:server.py


示例19: broadcast

            if '#' in txt or '@' in txt:
                word_list = txt.split(" ")
                send_list = []
                for word in word_list:
                    if '#' in word:
                        pub = word.replace("#", "")
                        temp = subs.get(pub)
                        if temp != None:
                            for h in temp:
                                if h not in send_list:
                                    send_list.append(h)
                    #Private Publish
                    if '@' in word:
                        privpub = word.replace("@", "")
                        if names.has_key(privpub):
                            privhandler = names[privpub]
                            if privhandler not in send_list:
                                send_list.append(privhandler)
                if send_list != None:
                    for h in send_list:
                        h.do_send({'speak': name, 'txt' : txt})
        
            #No topic in msg
            if "#" not in txt and "+" not in txt and "-" not in txt and "@" not in txt and txt != "":
                broadcast({'speak': name, 'txt': txt})


Listener(8888, MyHandler)
while 1:
    poll(0.05)
开发者ID:rhphung,项目名称:inf123,代码行数:30,代码来源:broker.py


示例20: beginGame

def beginGame():

    host, port = '169.234.87.121', 8888
    client = Client(host, port)

    has_lander = False
    game_over = False

    game_over_tick = 0


    while game_over_tick < 120:

        if game_over == True:
            game_over_tick += 1
            
        if should_exit == True:
            ##print('**** Disconnected from server ****')
            ##sys.exit()
            pass

        poll()
        
        windowSurfaceObj.fill(blackColor)


        pygame.draw.lines(windowSurfaceObj, greyColor, False, groundPoints)
        
        for x in particleList:
            pygame.draw.rect(windowSurfaceObj, greyColor, pygame.Rect(x[0], x[1], 2, 2))

        
        for x in landerList:
            if x[7] != 'DESTROYED':
                windowSurfaceObj.blit(pygame.transform.rotate(landerSurfaceObj, x[0]), (x[1], x[2]))

        for x in landerList:
            try:
                if x[4] == client.getPlayerID():
                    has_lander = True
                    myLander = x
            except:
                pass

        if has_lander:
                if myLander[5] != '':
                    game_over = True
                    gameWinLoseText = gameFont.render(myLander[5], True, greyColor)

        if has_lander:
            landerPlayerIdentifierText = gameFont.render('You', True, greyColor)
            windowSurfaceObj.blit(landerPlayerIdentifierText, (myLander[1], myLander[2] - 20))
            landerFuelText = gameFont.render('Lander Y Velocity: ' + str(myLander[6]), True, greyColor)
            windowSurfaceObj.blit(landerFuelText, (400, 30))

        if game_over:
            windowSurfaceObj.blit(gameWinLoseText, (30, 30))

        if has_lander:
            landerFuelText = gameFont.render('Lander Fuel: ' + str(myLander[3]), True, greyColor)
            windowSurfaceObj.blit(landerFuelText, (400, 50))

        userCommand = checkForKeyPress()

        sendCommandToServer(client, userCommand)

        
        pygame.display.update()
        fpsClock.tick(30)

    client.do_close()
开发者ID:sbetts,项目名称:123lunarlander,代码行数:71,代码来源:lunarlanderclient.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python network.Network类代码示例发布时间:2022-05-27
下一篇:
Python network.network函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap