To bring the IP and data you will need to change the function socket_recv
by function socket_recvfrom
About my previous answer, ignore her, that part I said on the "CLI doesn’t work", I was totally wrong :)
To get the data you need to edit the file class.PHPWebSocket.php
on lines 136 and 143:
...
foreach ($changed as $clientID => $socket) {
if ($clientID != 0) {
// client socket changed
$buffer = '';
$bytes = @socket_recvfrom($socket, $buffer, 4096, 0, $ipaddress, $port);/*$bytes = @socket_recv($socket, $buffer, 4096, 0);*/
if ($bytes === false) {
// error on recv, remove client socket (will check to send close frame)
$this->wsSendClientClose($clientID, self::WS_STATUS_PROTOCOL_ERROR);
}
elseif ($bytes > 0) {
echo $buffer, PHP_EOL;
echo 'IP: ', $ipaddress, ' e porta ', $port, PHP_EOL;
echo '-------------------------', PHP_EOL;
// process handshake or frame(s)
if (!$this->wsProcessClient($clientID, $buffer, $bytes)) {
...
Then on the terminal or CMD run the server.php
:
php5 ./server.php
Then open the file index.html
(by the file protocol also works) on two different browsers, Firefox and Opera for example and send a message from each of the browsers.
Look at the terminal/cmd screen and you will notice that you received two buffers with this:
GET / HTTP/1.1
Host: 127.0.0.1:9300
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: null
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/41.0.2272.118 Safari/537.36 OPR/28.0.1750.51
Accept-Encoding: gzip, deflate, lzma, sdch
Accept-Language: en-US,en;q=0.8
Sec-WebSocket-Key: MU8AuFEjzsMrwFh/R2gmZA==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
IP: 0.0.0.0 e porta 0
-------------------------
2015-04-25 04:08:11: 127.0.0.1 (1) has connected.
There’s nothing to be sorry about, we’re all here to learn :) ... Please delete the old comments. + 1 for question
– Guilherme Nascimento
@Guillhermenascimento in the waiting :]
– Vinícius Lara