-
-
Save amd64bit/0f7cb81995ab638f33fbabd6aad9fd0f to your computer and use it in GitHub Desktop.
[Python] Run UDP client for UDP socket 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
| #!/usr/bin/env python3 | |
| # | |
| # udpclient.py | |
| # | |
| # Required that UDP server runs on 127.0.0.1 port 8000. | |
| # See Gist udpserver.py. | |
| # | |
| # Send UDP message to UDP server. | |
| # | |
| # usage: python3 udpclient.py | |
| if __name__ == "__main__": | |
| import socket | |
| UDP_IP_ADDRESS_SERVER = "127.0.0.1" | |
| UDP_PORT_SERVER = 8000 | |
| message = "Hello, Server" | |
| client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
| print("Sending message '{}' to UDP server on {} port {} ...".format(message, UDP_IP_ADDRESS_SERVER, UDP_PORT_SERVER)) | |
| client.sendto(message.encode('utf-8'), (UDP_IP_ADDRESS_SERVER, UDP_PORT_SERVER)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment