Created
May 12, 2017 23:01
-
-
Save thobroni/b4b35acf0ce9e404056a79068d23e011 to your computer and use it in GitHub Desktop.
UDP client
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
| import socket | |
| import time | |
| import sys | |
| def main(): | |
| argc = len(sys.argv) | |
| addr = "127.0.0.1" | |
| PORT = 801 | |
| if(argc > 1): | |
| addr = sys.argv[1] | |
| if(argc > 2): | |
| PORT = sys.argv[2] | |
| print(addr) | |
| HOST = socket.gethostbyname(addr) | |
| print("Will send to {0}:{1}".format(HOST, PORT)) | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| while True: | |
| try: | |
| print("Sending") | |
| sock.sendto("Hi there".encode("UTF-8"), (HOST, PORT)) | |
| time.sleep(1) | |
| except socket.error as msg: | |
| sock.close() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment