Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Using socket datagrams (See related posts)

From Jeff Bauer's recipe.
   1  
   2  # server.py
   3  import socket
   4  port = 8081
   5  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
   6  s.bind(("", port))
   7  print "waiting on port:", port
   8  while 1:
   9      data, addr = s.recvfrom(1024)
  10      print data

   1  
   2  # client.py
   3  import socket
   4  port = 8081
   5  host = "localhost"
   6  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
   7  s.bind(("", 0))
   8  s.sendto("Holy Guido! It's working.", (host, port))

You need to create an account or log in to post comments to this site.


Click here to browse all 5309 code snippets

Related Posts