diff --git a/README.md b/README.md index 86546fc..d54328f 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ A server side alternative implementation of [socket.io](https://github.com/socketio/socket.io) in PHP based on [Workerman](https://github.com/walkor/Workerman).
# Notice -Only support socket.io v1.3.0 or greater.
+Only support socket.io >= v1.3.0 and <= v2.x
This project is just translate socket.io by [workerman](https://github.com/walkor/Workerman).
-More api just see http://socket.io/docs/server-api/ +More api just see [https://socket.io/docs/v2/server-api/](https://socket.io/docs/v2/server-api/) # Install composer require workerman/phpsocket.io @@ -138,6 +138,28 @@ $io->on('connection', function ($connection) use ($io) { Worker::runAll(); ``` +## Acknowledgement callback +```php + +use Workerman\Worker; +use PHPSocketIO\SocketIO; + +require_once __DIR__ . '/vendor/autoload.php'; + +$io = new SocketIO(2021); + +$io->on('connection', function ($connection) use ($io) { + $socket->on('message with ack', function ($data, $callback) use ($socket, $io) { + // acknowledgement callback + if ($callback && is_callable($callback)) { + $callback(0); + } + }); +}); + +Worker::runAll(); +``` + # 手册 [中文手册](https://github.com/walkor/phpsocket.io/tree/master/docs/zh) diff --git a/src/Socket.php b/src/Socket.php index d3cd322..6ca0424 100644 --- a/src/Socket.php +++ b/src/Socket.php @@ -346,7 +346,7 @@ public function onack($packet) call_user_func($ack, $packet['data']); unset($this->acks[$packet['id']]); } else { - echo ('bad ack '. packet.id); + echo ('bad ack '. $packet['id']); } }