React\Socket\ConnectionInterface::getRemoteAddress PHP Method

getRemoteAddress() public method

Returns the remote address (client IP) where this connection has been established from
public getRemoteAddress ( ) : string | null
return string | null remote address (client IP) or null if unknown
    public function getRemoteAddress();

Usage Example

Example #1
0
 /**
  * @param ConnectionInterface $conn
  */
 public function onConnection(ConnectionInterface $conn)
 {
     $labels = ['remote' => $conn->getRemoteAddress(), 'request_id' => Uuid::uuid4()->toString()];
     $request = new HttpdRequest($conn->getRemoteAddress(), $labels);
     $response = new HttpdResponse($conn, $labels);
     // Wire request and response event to global observer
     $request->subscribe($this->observable);
     $response->subscribe($this->observable);
     // Remote connection closed, notify everything's done
     $conn->on("end", [$request, 'notifyCompleted']);
     $conn->on("end", function () use($response, $labels) {
         $response->notifyNext(new Event("/httpd/connection/closed", $response, $labels));
         $response->notifyCompleted();
     });
     // No observers we can't do anything
     if (!$this->observers) {
         $response->sendError("No route defined", 404);
         return;
     }
     $parser = new RequestParser($request);
     $conn->on('data', array($parser, 'parse'));
     // Head is received we can dispatch route
     $request->take(1)->subscribeCallback(function () use($request, $response, $labels) {
         $this->dispatch($request, $response, $labels);
     });
 }
All Usage Examples Of React\Socket\ConnectionInterface::getRemoteAddress
ConnectionInterface