Skip to content

Instantly share code, notes, and snippets.

@mhtsai1010
Last active August 22, 2016 04:07
Show Gist options
  • Save mhtsai1010/62c56e96d5d58325c06a to your computer and use it in GitHub Desktop.
Save mhtsai1010/62c56e96d5d58325c06a to your computer and use it in GitHub Desktop.
Python: udp client sockets
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
target_host = "127.0.0.1"
target_port = 80
# create a socket object
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# send some data
client.sendto("input some data here", (target_host, target_port))
# receive some data
(data, addr) = client.recvfrom(4096)
# print response
print data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment