Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import socket
  2.  
  3.  
  4. class UDP_server:
  5.     def __init__(self):
  6.         self.listenToClient()
  7.  
  8.     def listenToClient(self):
  9.         with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
  10.             sock.bind(("localhost", 14567))
  11.             page = ""
  12.             while True:
  13.                 data, addr = sock.recvfrom(1024)
  14.                 page = page + data.decode("utf-8")
  15.             print(page)
  16.  
  17.  
  18. if __name__ == "__main__":
  19.     UDP_server().__init__()
  20.  
  21.  
  22. ____________________________________________
  23.  
  24. import socket
  25.  
  26.  
  27. class UDP_client:
  28.     def __init__(self):
  29.         self.SendTo()
  30.  
  31.     def SendTo(self):
  32.         with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
  33.             sock.sendto("Zamechatelnoe nynche utro, sudaryna", ("localhost", 14567))
  34.  
  35.  
  36. if __name__ == 'main':
  37.     UDP_client.__init__()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement