Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #sender
  2. import socket
  3. UDP_IP = "127.0.0.1"
  4. UDP_PORT = 5005
  5. MESSAGE = "Hello, World!"
  6. print "UDP target IP:", UDP_IP
  7. print "UDP target port:", UDP_PORT
  8. print "message:", MESSAGE
  9. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  10.  
  11. sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
  12.  
  13.  
  14. #receiver
  15. import socket;
  16.  
  17. UDP_IP = "127.0.0.1"
  18.  
  19. UDP_PORT = 5005
  20.  
  21. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  22.  
  23. sock.bind((UDP_IP, UDP_PORT))
  24.  
  25. while True:
  26. data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
  27. print "received message:", data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement