code: def close_stream(self):
          
          if not self.is_connected:
              return
  
          self.stream.close()
          self.state = DISCONNECTED
          self.on_close.send(self)
docs: Close the underlying socket.