Skip to content

Instantly share code, notes, and snippets.

@sparrc
Last active August 3, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sparrc/42422743b72bdfe172e00b95933f87b6 to your computer and use it in GitHub Desktop.
Save sparrc/42422743b72bdfe172e00b95933f87b6 to your computer and use it in GitHub Desktop.
import socket
SOCKET_SIZE = 4096
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("localhost", 8009))
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, SOCKET_SIZE)
while True:
try:
msg, host = sock.recvfrom(SOCKET_SIZE)
# print(msg)
print("RECV {} byte payload from {}:{} ->\n{}"\
.format(len(str(msg)), host[0], host[1], msg))
except KeyboardInterrupt:
print("")
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment