Skip to content

Commit 5dd2cbd

Browse files
committed
basic udp client sending request to localhost
1 parent a1df584 commit 5dd2cbd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

udp-client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import socket
2+
3+
# can't find a udp server so using local settings
4+
5+
target_host = "127.0.0.1"
6+
target_port = 9997
7+
8+
# create a socket object with datagram settings
9+
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
10+
11+
# send data to the target host, port
12+
client.sendto(b"AAAABBBBCCCC", (target_host, target_port))
13+
14+
# receive data from the server and deconstruct the data and address received
15+
data, addr = client.recvfrom(4906)
16+
17+
print(data.decode(), addr)
18+
19+
client.close()

0 commit comments

Comments
 (0)