devices = []; // Create the request $request = new MSearchRequest(); $request->setSearchType($search_type); $request->setMaxWait($timeout-1); // Send the request and wait for responses $responses = $endpoint->send($request, $timeout); foreach ($responses as $response) { // Add the relevant responses to the list if ($response instanceof MSearchResponse) { $loc = $response->getLocation(); if (array_key_exists($loc, $this->devices)) { continue; } $device = Device::createFromSchema($response->getLocation(), $response->getIp()); if ($device) { $this->devices[$loc] = $device; } } } $this->devices = array_values($this->devices); return count($this->devices); } public function getIterator() { return new ArrayIterator($this->devices); } public function jsonSerialize() { return $this->devices; } }