hello,
i got a project to create a UDP broadcast programming -
create a system that sends a broadcast of a message alert to all the systems that are on the network.
Each station that receives the message must transmit it to other stations on the networks it is connected to spread the message.
i created the client.py and the server.py , but i don't know how to make the station transmit the message alert.
its the first time i am creating a project in networking programming in python.
i got a project to create a UDP broadcast programming -
create a system that sends a broadcast of a message alert to all the systems that are on the network.
Each station that receives the message must transmit it to other stations on the networks it is connected to spread the message.
i created the client.py and the server.py , but i don't know how to make the station transmit the message alert.
its the first time i am creating a project in networking programming in python.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
##client import socket, time SERVER_ADDRES = "127.0.0.1" SERVER_PORT = 10000 #connect to server client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP address = (SERVER_ADDRES,SERVER_PORT) client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1 ) client.bind(("", 37020 )) while True : data, address = client.recvfrom( 1024 ) print (data) client.sendto(data, ( '<broadcast>' , 12345 )) break |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
##server import socket import time SERVER_ADDRESS = "localhost" SERVER_PORT = 10000 # create a socket server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1 ) server.settimeout( 0.2 ) address = (SERVER_ADDRESS,SERVER_PORT) print ( f "server {SERVER_ADDRESS} at port {SERVER_PORT}" ) server.bind(("", 44444 )) message = b "Red Alert" while True : # broadcast server.sendto(message, ( '<broadcast>' , 37020 )) print ( "message sent!" ) time.sleep( 1 ) break |