title: Python 3.X Unix Socket Example
body: <p>I have been searching the last couple of hours on finding a simple Server / Client Unix Socket Example.  I have found examples for Python 2.X, but I am failing at finding one that works for Python 3.X. </p>
  
  <p>I keep getting TypeErrors.</p>
  
  <p>The example that I have been working with is:</p>
  
  <p><strong>client.py</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  import socket
  import os
  # import os, os.path
  
  print("Connecting...")
  if os.path.exists("/tmp/python_unix_sockets_example"):
      client = socket.socket( socket.AF_UNIX, socket.SOCK_DGRAM )
      client.connect("/tmp/python_unix_sockets_example")
      print("Ready.")
      print("Ctrl-C to quit.")
      print("Sending 'DONE' shuts down the server and quits.")
      while True:
  #        try:
              x = input( "&gt; " )
              if "" != x:
              print("SEND:", x)
                  client.send( x )
                  if "DONE" == x:
                      print("Shutting down.")
                  break
  #        except KeyboardInterrupt, k:
  #            print("Shutting down.")
      client.close()
  else:
      print("Couldn't Connect!")
      print("Done")
  </code></pre>
  
  <ul>
  <li>With the client portion, I was not sure how to get a KeyboardInterupt to work in 3.X, so I killed the Try and Except portions.  Any Advice?</li>
  <li>Also, the syntax from the example I used had multiple modules being loaded from one import
  import os, os.path
  Is this the old way of only loading os.path from os module? </li>
  </ul>
  
  <p><strong>server.py</strong></p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  import socket
  import os
  # import os, os.path
  # import time
  
  if os.path.exists("/tmp/python_unix_sockets_example"):
      os.remove("/tmp/python_unix_sockets_example")
  
  print("Opening socket...")
  server = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
  server.bind("/tmp/python_unix_sockets_example")
  
  print("Listening...")
  while True:
      datagram = server.recv(1024)
  
      if not datagram:
          break
      else:
          print("-" * 20)
          print(datagram)
          if "DONE" == datagram:
              break
  print("-" * 20)
  print("Shutting down...")
  server.close()
  os.remove("/tmp/python_unix_sockets_example")
  print("Done")
  </code></pre>
  
  <ul>
  <li><p>When I run this I get TypeError: 'str' does not support the buffer interface.</p></li>
  <li><p>Does Python 3.4 Unix Sockets only support binary?</p></li>
  <li><p>What is the easiest way to make this work?</p></li>
  </ul>
  
  <p>Thanks in advance!</p>