Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the remote IP address #266

Closed
uribes78 opened this issue Jul 18, 2021 · 3 comments
Closed

How can I get the remote IP address #266

uribes78 opened this issue Jul 18, 2021 · 3 comments

Comments

@uribes78
Copy link

uribes78 commented Jul 18, 2021

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
Copy link
Owner

walkor commented Jul 22, 2021

#15

@walkor
Copy link
Owner

walkor commented Jul 22, 2021

$io->on('connection', function($socket)use($io){
        var_dump($socket->conn->remoteAddress);
});

Will display like ip:port format.

@uribes78
Copy link
Author

Got it. Thanks @walkor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants