Skip to content

Instantly share code, notes, and snippets.

@amd64bit
Forked from glegoux/udpclient.py
Created April 20, 2018 04:34
Show Gist options
  • Save amd64bit/0f7cb81995ab638f33fbabd6aad9fd0f to your computer and use it in GitHub Desktop.
Save amd64bit/0f7cb81995ab638f33fbabd6aad9fd0f to your computer and use it in GitHub Desktop.
[Python] Run UDP client for UDP socket server
#!/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