SHARE
TWEET

Untitled

a guest Apr 19th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2.  
  3.  # create our udp socket
  4.  try:
  5.      socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  6.  except socket.error:
  7.      print("Oops, something went wrong connecting the socket")
  8.      exit()
  9.  
  10.  while 1:
  11.      message = input("> ")
  12.  
  13.      # encode the message
  14.      message = message.encode()
  15.  
  16.      try:
  17.          # send the message
  18.          socket.sendto(message, ("serverip", 9999))
  19.  
  20.          # output the response (if any)
  21.          data, ip = socket.recvfrom(1024)
  22.  
  23.          print("{}: {}".format(ip, data.decode()))
  24.  
  25.      except socket.error:
  26.          print("Error! {}".format(socket.error))
  27.          exit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top