walkor / phpsocket.io

A server side alternative implementation of socket.io in PHP based on workerman.
2.3k stars 508 forks source link

How can I get the remote IP address #266

Closed uribes78 closed 3 years ago

uribes78 commented 3 years ago

Hi, I'm trying to get the remote address IP from current connection, because I need to make a ACL service using the IP.

This is part of my code:

$wss = new SocketIO(8084);

$wss->on("connection", function ($socket) use ($wss) {
    $socket->on("ready", function ($msg) use ($socket) {
        print "Ready received: {$socket->id}@{$socket->getRemoteIP()}\n";
        $socket->emit("ack", $msg);
    });
});

But is not working, any advice? Thanks anyway

walkor commented 3 years ago

https://github.com/walkor/phpsocket.io/issues/15

walkor commented 3 years ago
$io->on('connection', function($socket)use($io){
        var_dump($socket->conn->remoteAddress);
});

Will display like ip:port format.

uribes78 commented 3 years ago

Got it. Thanks @walkor