hello,
A few days ago I was asked you about broadcasting a message among set of raspberry pis
I am create the system that sends a broadcast of a message alert to all the nodes that are on the network.
Now I want each station that receives the message must transmit it to other stations on the networks it is connected except the sender to spread the message.
i created the client.py and the server.py , but I don't know how to make the station re-transmit the message to all except the sender one .
its the first time i am creating a project in networking programming in python.
#client.py
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
client.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
client.bind(("", 50000))
while True:
data, addr = client.recvfrom(1024)
print(('received message:') , data.decode("utf-8"))
#server.py
import socket
import time
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
server.settimeout(0.2)
MSG = 'Hello, World!'
MESSAGE = str.encode(MSG)
while True:
server.sendto(MESSAGE, ('<broadcast>', 50000))
print("message sent!")
time.sleep(1)