title: SOL_SOCKET and SOL_REUSE
body: <p>I'm trying to set up a socket for p2p communication. A I found this code, but I'm having a hard time understanding the code. What does SOL_SOCKET, as well as SOL_REUSE?</p>
  
  <p>Could someone help me go through this code?</p>
  
  <pre><code>#!/usr/bin/env python
  import socket, sys
  
  self_broken = False
  
  def wait(c):
      print('waiting...')
      c.send('waiting')
      broken = True
      while broken:
          status = c.recv(1024)
          if status == 'working':
              print(status)
              if self_broken:
                  c.send('broken')
              else:
                  c.send('starting')
                  broken = False
      c.close()
  
  def main():
      s = socket.socket()
      s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      host, port = socket.gethostname(), 10001
      s.bind((host, port))
      s.listen(1)
      while True:
          c, addr = s.accept()
          status = c.recv(1024)
          print(addr[0] + ':' + str(addr[1]) + ' &gt; ' + status)
          if status == 'broken':
              wait(c)
          else:
              print(status)
          c.close()
      s.close()
  
  main()
  </code></pre>
  
  <p>I found this explanation, but it is for C, does it apply for Python as well?
  <a href="https://stackoverflow.com/questions/21515946/sol-socket-in-getsockopt">This is for C, is it the same for Python?</a></p>
  
  <p>EDIT:
  Can anyone tell med what the 'c' does? it's in wait(c), c.send and c.close. </p>