Python Forum
Udp broadcast programming project
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Udp broadcast programming project
#1
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.

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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020