code: def connect(self):
          
          if self.state == DISCONNECTED:
              raise errors.NSQException('connection already closed')
  
          if self.is_connected:
              return
  
          stream = Stream(self.address, self.port, self.timeout)
          stream.connect()
  
          self.stream = stream
          self.state = CONNECTED
          self.send(nsq.MAGIC_V2)
docs: Initialize connection to the nsqd.