protocol

说明:

  1. string Connection::$protocol

设置当前连接的协议类

范例

  1. use Workerman\Worker;
  2. require_once __DIR__ . '/Workerman/Autoloader.php';
  3. $worker = new Worker('tcp://0.0.0.0:8484');
  4. $worker->onConnect = function($connection)
  5. {
  6. $connection->protocol = 'Workerman\\Protocols\\Http';
  7. };
  8. $worker->onMessage = function($connection, $data)
  9. {
  10. var_dump($_GET, $_POST);
  11. // send 时会自动调用$connection->protocol::encode(),打包数据后再发送
  12. $connection->send("hello");
  13. };
  14. // 运行worker
  15. Worker::runAll();