SOCKET连接接收不到数据

longda1982 2008-01-11 12:37:47
现在手头有个项目要建立PHP(client)和JAVA(server)的SOCKET连接,传递数据:

现在SOCKET连接建立是成功的,而且PHP发过来的测试数据,在SERVER端也是收的到的

问题是SERVER发出的数据,在PHP接收不到。请问各位有何看法啊?

背景资料:
1.SERVER端发送数据应该是成功的(不确定),因为并没有任何报错
2.PHP老是出现这样的警告:
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in G:\AppServ\www\sock\index1.php on line 4

第4行:if (! ($fd = fsockopen("192.168.0.103",8888,&$error_number,&$error_des,60)))

3.PHP接受数据用的
echo fgets($fd,100000);

4. JAVA端发送数据是:
OutputStream out = clientSocket.getOutputStream();
PrintWriter out1 = new PrintWriter(out,true);
out1.println("我是007");
...全文
480 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
阳光csdn 2012-10-24
  • 打赏
  • 举报
回复
学习中,帮顶,求高人讲解php如何获取java socket接口数据
songzairan 2008-09-08
  • 打赏
  • 举报
回复
顶一个!学习....
zealVampire 2008-04-23
  • 打赏
  • 举报
回复
fsockopen("192.168.0.103",8888,&$error_number,&$error_des,60)))

把&去掉, 即使是传应用,PHP4, 5默认只要在函数实现那里加&即可。

fsockopen好像只能用在linux下还是咋的, 去看看PHP reference吧

<?php
error_reporting(E_ALL);

echo "<h2>TCP/IP Connection</h2>\n";

/* Get the port for the WWW service. */
$service_port = getservbyname('www', 'tcp');

/* Get the IP address for the target host. */
$address = gethostbyname('www.example.com');

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "OK.\n";
}

echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "OK.\n";
}

$in = "HEAD / HTTP/1.1\r\n";
$in .= "Host: www.example.com\r\n";
$in .= "Connection: Close\r\n\r\n";
$out = '';

echo "Sending HTTP HEAD request...";
socket_write($socket, $in, strlen($in));
echo "OK.\n";

echo "Reading response:\n\n";
while ($out = socket_read($socket, 2048)) {
echo $out;
}

echo "Closing socket...";
socket_close($socket);
echo "OK.\n\n";
?>
老紫竹 2008-01-11
  • 打赏
  • 举报
回复
out1.println("我是007");
out1.flush();


pass-by-reference 在php.inc里面能找到对应的配置。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧