We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8913607 commit f957f39Copy full SHA for f957f39
socket/basic-UDP/README.md
@@ -0,0 +1,14 @@
1
+# UDP example
2
+
3
+Minimal UDP server for single client.
4
5
+You can test with `netcat` as client with `-u` for UDP
6
7
+````
8
+$ nc -u localhost 3000
9
10
11
+---
12
13
+- [netcat Homepage](http://netcat.sourceforge.net/)
14
+- [netcat Wikipedia](https://en.wikipedia.org/wiki/Netcat)
socket/basic-UDP/main.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+#
+# you can test with `netcat` as client with `-u` for UDP
+# $ nc -u localhost 3000
+import socket
+s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+s.bind(('127.0.0.1', 3000))
+while True:
15
+ data, address = s.recvfrom(1024)
16
+ print(data.decode('ascii'), end='')
17
+ s.sendto(data, address)
0 commit comments