Index.php 750 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. class Index extends Controller
  5. {
  6. public function index(){
  7. return $this->view->fetch();
  8. }
  9. public function test()
  10. {
  11. $st="test/test";
  12. $length = strlen($st);
  13. //创建tcp套接字
  14. $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
  15. //连接tcp
  16. socket_connect($socket, '121.5.123.166',2347);
  17. //向打开的套集字写入数据(发送数据)
  18. $s = socket_write($socket, $st, $length);
  19. //从套接字中获取服务器发送来的数据
  20. /*while(true){*/
  21. $msg = socket_read($socket,2347);
  22. echo $msg;
  23. /*sleep(1);
  24. }*/
  25. //关闭连接
  26. socket_close($socket);
  27. }
  28. }