Index.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. class Index extends Frontend
  5. {
  6. protected $noNeedLogin = '*';
  7. protected $noNeedRight = '*';
  8. protected $layout = '';
  9. public function test1(){
  10. // 文本加一个回车
  11. $buffer1 = 'abcdefghijklmn';
  12. // 在php中双引号中的\n代表一个换行符,例如"\n"
  13. $buffer2 = '{"type":"say", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello", "content":"hello"}'."";
  14. $buffer2 = 'abcdefghijklmn'."\n";
  15. // 与服务端建立socket连接
  16. $client = stream_socket_client('tcp://1.14.197.70:2349');
  17. // 以text协议发送buffer1数据
  18. //fwrite($client, $buffer1);
  19. // 以text协议发送buffer2数据
  20. fwrite($client, $buffer2);
  21. }
  22. public function index()
  23. {
  24. return $this->view->fetch();
  25. }
  26. }