123456789101112131415161718192021222324 |
- import socket
- import threading
-
- class Broadcast():
- def __init__(self,broadcast, broadcastPort):
- msg = bytes("Hello, Who can do somthing for me? Tnx",'utf-8')
- self.onlineOracles=[]
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
- self.sock.sendto(msg,(broadcast, broadcastPort))
- t1 = threading.Thread(target=self.listen)
- t1.start()
- print("Broadcast sended")
- def listen(self):
- while True:
- msg, addr = self.sock.recvfrom(32)
- self.onlineOracles.append((addr[0],msg.decode("utf-8")))
- # print("message",msg," from ",addr)
|