PHP作为客户端与C++服务器端进行Socket通信问题,急求 50
PHP客户端代码如下,怎样编写C++服务器端代码能跟它无错误连接啊?<?php$info=$_POST[info];error_reporting(E_ALL);set_...
PHP客户端代码如下,怎样编写C++服务器端代码能跟它无错误连接啊?
<?php
$info=$_POST[info];
error_reporting(E_ALL);
set_time_limit(0);
echo "<h2>TCP/IP Connection</h2>";
$port=1935;
$ip="192.168.249.18";
$socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
echo $socket;
if($socket < 0){
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
}
echo "试图连接'$ip'端口'$port'...\n<br>";
$result=socket_connect($socket, $ip, $port);
if($result < 0){
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
}else{
echo "连接成功!<br>";
}
$out='';
if(!socket_write($socket, $info, strlen($info))){
echo "socket_write() failed: reason: " . socket_strerror($socket) . "\n";
}else{
echo "发送到服务器信息成功!<br>";
echo "发送的内容为:<p><font color='red'>$info</font></p>";
}
while($out = socket_read($socket, 8192)){
echo "接收服务器回传信息成功!\n";
echo "回传的信息为:";
?>
<form name="form" method="post" action="test/helpindex.php" target="main">
<input name="back" type="text" value="<?php echo $out;?>" size="25" />
<input type="submit" name="submit" value="执行" />
</form>
<?php
}
socket_close($socket);
echo "</br>成功关闭SOCKET!";
?> 展开
<?php
$info=$_POST[info];
error_reporting(E_ALL);
set_time_limit(0);
echo "<h2>TCP/IP Connection</h2>";
$port=1935;
$ip="192.168.249.18";
$socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
echo $socket;
if($socket < 0){
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
}
echo "试图连接'$ip'端口'$port'...\n<br>";
$result=socket_connect($socket, $ip, $port);
if($result < 0){
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
}else{
echo "连接成功!<br>";
}
$out='';
if(!socket_write($socket, $info, strlen($info))){
echo "socket_write() failed: reason: " . socket_strerror($socket) . "\n";
}else{
echo "发送到服务器信息成功!<br>";
echo "发送的内容为:<p><font color='red'>$info</font></p>";
}
while($out = socket_read($socket, 8192)){
echo "接收服务器回传信息成功!\n";
echo "回传的信息为:";
?>
<form name="form" method="post" action="test/helpindex.php" target="main">
<input name="back" type="text" value="<?php echo $out;?>" size="25" />
<input type="submit" name="submit" value="执行" />
</form>
<?php
}
socket_close($socket);
echo "</br>成功关闭SOCKET!";
?> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询