本文整理汇总了Python中socket.socket.sendto函数的典型用法代码示例。如果您正苦于以下问题:Python sendto函数的具体用法?Python sendto怎么用?Python sendto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sendto函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: announce_bc
def announce_bc(socket, port, name, world):
'''This function acts to broadcast the server's
status of operation. Whether it's alive and
ready to accept new players, or dead.
'''
print 'Broadcasting thread started!'
dest = ('<broadcast>', port)
alive = True
while alive:
if world.keep_alive:
message = "\HELLO;"+name
socket.sendto(message, dest)
if not world.keep_alive:
message = "\DIE"
for _ in range(3):
socket.sendto(message, dest)
sleep(0.2)
alive = False
#Try to sleep up to 5 seconds before broadcasting again.
for _ in range(20):
if world.keep_alive:
sleep(0.25)
else:
break
print "Broadcasting thread closed!"
socket.close()
开发者ID:kristapsdreija,项目名称:Frogs-vs-Flies,代码行数:26,代码来源:server.py
示例2: sender
def sender(self, socket):
logger.debug('Waiting for events')
# subscribe
self.eventbus.subscribe("core")
self.eventbus.subscribe("plugin")
# listen for events
for event in self.eventbus.listen():
logger.debug("Event received: " + event.to_json())
if(event.name == "device.push"):
packet = Packet()
packet.dst = 25
packet.src = 1
packet.cmd = event.name
packet.data = event.data
#logger.debug("packet to send: " + packet.to_json())
addr = self.cache.get(packet.dst)
if(addr == None):
logger.error("Address not found for device: " + str(packet.dst))
continue
address = addr.split(":")
#address = ["192.168.1.1", 4444]
# send packet
socket.sendto(packet.to_json(), (address[0], int(address[1])))
logger.debug("Packet sent: " + packet.to_json() + " to: " + str(address))
continue
开发者ID:jurex,项目名称:reactor,代码行数:34,代码来源:ethernet.py
示例3: sendto
def sendto(self, data, flags_or_addr, addr=None):
self._checkClosed()
if self._sslobj:
raise ValueError('sendto not allowed on instances of %s' % self.__class__)
else:
if addr is None:
return socket.sendto(self, data, flags_or_addr)
return socket.sendto(self, data, flags_or_addr, addr)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:8,代码来源:ssl.py
示例4: while
socket, info = ss.accept()
while (True):
commande = socket.recv(16)
commande = commande.decode()
print(commande)
socket.send((sys.argv[1] + "\rtoast\n").encode())
if commande == "1":
nom = socket.recv(512)
nom = nom.decode()
c = findContactByNom(lContact, nom)
socket.sendto(c)
if commande == "2":
nom = socket.recv(512)
nom = nom.decode()
c = findContactByTel(liste, tel)
socket.send(c)
if commande == "3":
nom = socket.recv(512)
tel = socket.recv(4)
nom = nom.decode()
tel = tel.decode()
开发者ID:CamTosh,项目名称:Cours-Python,代码行数:30,代码来源:__init__.py
注:本文中的socket.socket.sendto函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论