PHP TCP客户端无法连接到服务器

时间:2012-09-16 03:29:49

标签: php tcp client

我已经收集了一些将TCP clinet连接到服务器并更改了IP的示例,但我真的不知道我的代码中的错误是什么,因为它应该可以工作,服务器也在线,来自Gta San Andrease Multiplayer脚本控制台,服务器在我的其他电脑的本地主机上,使用ip 192.168.0.11,服务器端口是7777,这是我的PHP网站的客户端代码:

 <?php

  // form submitted
  // where is the socket server?
  $host="192.168.0.11";
  $port = 7777;
  // open a client connection
  echo "1";
  $fp = fsockopen ($host, $port, $errno, $timeout);
  echo "2";
  if (!$fp){
  echo "3";
  $result = "Error: could not open socket connection";
  }
  else
  {
 echo "4";
  // get the welcome message
  fgets ($fp, 7777);
  // write the user string to the socket
  fputs ($fp, $message);
  // get the result
  $result .= fgets ($fp, 7777);
  // close the connection
  fputs ($fp, "END");
  fclose ($fp);
  // trim the result and remove the starting ?
  $result = trim($result);
  $result = substr($result, 2);
  // now print it to the browser
  }
  ?>
  Server said: <b><? echo $result; ?></b>
  <?

  ?>

这是警告/错误:

警告:fsockopen():无法连接到192.168.0.11:7777(连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败。)

0 个答案:

没有答案