encoder = (new EncoderFactory())->create(); $this->decoder = (new DecoderFactory())->create(); } protected function send(Message $message) : Promise { $data = $this->encoder->encode($message); return $this->write($data); } protected function receive() : Promise { return call(function () { $data = (yield $this->read()); if ($data === null) { throw new DnsException("Reading from the server failed"); } return $this->decoder->decode($data); }); } public function isAlive() : bool { return \true; } }