final public function close()
    {

        $this->onCloseConnection();

        if($this->socket){
            $this->write("</stream:stream>");
            parent::close();
            $this->connected = false;
        }

    }