public function connect($renew=false)
    {
        if(!$renew && $this->isConnnected()) {
            return $this;
        }else if($renew && $this->isConnnected()){
            $this->close();
        }
        
        $this->beforeConnect();
        
        $this->socket =  stream_socket_client($this->target,$errno, $errstr, 0, $this->connect_flag, $this->context);
        if(!$this->socket || $errno) {
            Yii::error("connect error($this->target) $errstr $errno", 'beyod');
            $this->trigger(Server::ON_CONNECT_FAILED, new ErrorEvent(['code'=>$errno, 'errstr'=>$errstr]));
            return ;
        }
        
        stream_set_blocking($this->socket, 0);
        
        if($this->isTCP() || $this->isUnix()){
            $this->timeoutLimit();
            Yii::$app->eventLooper->addFdEvent($this->socket, EventLooper::EV_WRITE, [$this, 'checkConnectResult']);
        }else{
            Yii::$app->eventLooper->addFdEvent($this->socket, EventLooper::EV_READ, [$this, 'readBuffer']);
        }
        
        if($this->sendBuffer) {
            $this->baseWrite();
        }
        
        return $this;
    }