Created
April 10, 2015 17:10
-
-
Save Averroes/6adf312dbb4c71fdb6a8 to your computer and use it in GitHub Desktop.
creating a udp server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from socket import socket, AF_INET, SOCK_DGRAM | |
| import time | |
| def time_server(address): | |
| sock = socket(AF_INET, SOCK_DGRAM) | |
| sock.bind(address) | |
| while True: | |
| msg, addr = sock.recvfrom(8192) | |
| print('Got message from', addr) | |
| resp = time.ctime() | |
| sock.sendto(resp.encode('ascii'), addr) | |
| if __name__ == '__main__': | |
| time_server(('', 20000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment