title: Automatically reconnect client socket on server shutdown?
body: <p>So, I've had a problem this morning that I couldn't find any posted answers yet. Basically, I wanted to have my Python client to reconnect everytime the server shuts down.</p>
  
  <p>My previous code looks like this</p>
  
  <pre><code> def fire(self):
       self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       self.s.settimeout(5)
  
       while (self.connected):
           # create the transmission_struct class
  
           msg = transmission_struct(self.stream, self.CHUNK, self.rate)
  
           # create the Filestream packet
  
           packet1 = msg.structure_msg_fls()
  
           # create the decision packet
  
           packet2 = msg.structure_msg_stm()
  
           # send, first the decision packet
           self.s.sendall(packet2)
  
           # send the whole packet one by one
  
           for i in range(len(packet1)):
               self.s.sendall(packet1[i])
  
           # timestamp for debugging purposes
  
           ts = time.time()
           timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
           print(timestamp + " size of data sent is " + str(len(packet1)) +
                 " size of decision is " + str(len(packet2)))
  </code></pre>