【发布时间】:2014-12-16 05:52:40
【问题描述】:
我的 html 页面中有三个按钮连接到 php 脚本,它们使用套接字连接将命令发送到另一个应用程序。
1) 当应用程序接收命令和 xampp 服务器在 localhost 上运行时,它工作正常,但是当我尝试在网络上发送命令时,它有时可以工作,有时不能。
2) 这背后的原因是什么。
按钮 1 的代码
<?php
// Fill up array with names
$q=$_GET["q"];
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$host = $_GET["vz"];
$port=6100;
$buffer=$q ."\0";
$len= strlen($buffer);
socket_connect($sock, $host, $port);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
$buffer='COMMAND HERE';
$len= strlen($buffer);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
echo( socket_read($sock, 65535) );
socket_close($sock);
?>
按钮 2 的代码
?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$host = $_GET["x"];
$port=6100;
$buffer='COMMAND HERE';
$len= strlen($buffer);
socket_connect($sock, $host, $port);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
$len= strlen($buffer);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
echo( socket_read($sock, 65535) );
socket_close($sock);
?>
按钮 3 的代码
<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$host = $_GET["x"];
$port=6100;
$buffer='COMMAND HERE';
$len= strlen($buffer);
socket_connect($sock, $host, $port);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
$len= strlen($buffer);
socket_sendto($sock, $buffer, $len, 0 , $host, $port);
echo( socket_read($sock, 65535) );
socket_close($sock);
?>
【问题讨论】:
标签: javascript php html