From 7083a314b9450026aecef03662cd8ee963610919 Mon Sep 17 00:00:00 2001 From: soif Date: Tue, 23 May 2017 09:17:29 +0200 Subject: [PATCH] Get remote peer address and port --- sock/SocketClient.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sock/SocketClient.php b/sock/SocketClient.php index 22491d4..65c053d 100644 --- a/sock/SocketClient.php +++ b/sock/SocketClient.php @@ -7,6 +7,9 @@ class SocketClient { private $connection; private $address; private $port; + + private $peer_address; + private $peer_port; public function __construct( $connection ) { $address = ''; @@ -15,6 +18,10 @@ public function __construct( $connection ) { $this->address = $address; $this->port = $port; $this->connection = $connection; + + socket_getpeername($connection, $address, $port); + $this->peer_address =$address; + $this->peer_port =$port; } public function send( $message ) { @@ -37,8 +44,16 @@ public function getPort() { return $this->port; } + public function getPeerAddress() { + return $this->peer_address; + } + + public function getPeerPort() { + return $this->peer_port; + } + public function close() { socket_shutdown( $this->connection ); socket_close( $this->connection ); } -} +}