本文整理汇总了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()
示例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
示例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)
示例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()