Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. Code running on PC:
  2. import os
  3. from socket import *
  4. host = "192.168....." (IP address of pi)
  5. port = 13000
  6. addr = (host, port)
  7. UDPSock = socket(AF_INET, SOCK_DGRAM)
  8. while True:
  9. data = raw_input("Enter message to send or type 'exit': ")
  10. UDPSock.sendto(data, addr)
  11. if data == "exit":
  12. break
  13. UDPSock.close()
  14. os._exit(0)
  15.  
  16. Code running on Pi:
  17.  
  18. import os
  19. from socket import *
  20. host = ""
  21. port = 13000
  22. buf = 1024
  23. addr = (host, port)
  24. UDPSock = socket(AF_INET, SOCK_DGRAM)
  25. UDPSock.bind(addr)
  26. print ("Waiting to receive messages...")
  27. while True:
  28. (data, addr) = UDPSock.recvfrom(buf)
  29. print ("Received message: " + data)
  30. if data == "exit":
  31. break
  32. UDPSock.close()
  33. os._exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement