public function close() {
        if(!empty($this->socket)) {
            if($this->socketsEnabled) {
                socket_close($this->socket);
            } else {
                fclose($this->socket);
            }
            $this->socket = null;
        }
    }