我有一个noob问题 - 我创建了一个非常简单的HTML页面,当按下按钮时,通过我的网络将一串串行数据发送到以太网到串行转换器。它控制音频矩阵开关(通过其串行端口)。网页工作,它切换音频矩阵,但在我点击一个按钮后,浏览器无限期地等待响应。我可以点击其他按钮并仍然进行切换,但它总是在等待响应。如何从该远程设备获取响应并在网页上显示(或对其进行操作),并使页面无限期等待?这是将此数据字符串发送到远程IP的正确方法,还是有更好的方法?这是代码:
<html>
<head>
</head>
<body bgcolor="#808080">
<div align="center">
<p><font size="7" face="Arial" color="#FFFFFF">Audio Control</font></p>
<div
<div style="width:500px;height:175px;border:1px solid white;">
<p align="left"><font size="6" face="Arial" color="#FFFFFF">Backyard</font></p><hr>
<form action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Tuner" id="Backyard Tuner" name="CL1I1O1T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<form action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Computer" id="Backyard Computer" name="CL1I2O1T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<form action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Apple TV" id="Backyard Apple TV" name="CL1I3O1T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<form action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="iPod" id="Backyard iPod" name="CL1I4O1T" class="auto- style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Off" id="Backyard Off" name="DL1O1T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<p align="left"> </p>
<p align="left"> </p>
<p align="left"> </p>
<div
<div style="width:500px;height:175px;border:1px solid white;">
<p align="left"><font size="6" face="Arial" color="#FFFFFF">Garage</font></p><hr>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Tuner" id="Garage Tuner" name="CL1I1O2T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Computer" id="Garage Computer" name="CL1I2O2T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Apple TV" id="Garage Apple TV" name="CL1I3O2T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="iPod" id="Garage iPod" name="CL1I4O2T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Off" id="Garage Off" name="DL1O2T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<div align="center">
<p align="left"> </p>
<p align="left"> </p>
<p align="left"> </p>
<div
<div style="width:500px;height:175px;border:1px solid white;">
<p align="left"><font size="6" face="Arial" color="#FFFFFF">Family Room</font></p><hr>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Tuner" id="Family Room Tuner" name="CL1I1O3T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Computer" id="Family Room Computer" name="CL1I2O3T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Apple TV" id="Family Room Apple TV" name="CL1I3O3T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="iPod" id="Family Room iPod" name="CL1I4O3T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Off" id="Family Room Off" name="DL1O3T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<div align="center">
<p align="left"> </p>
<p align="left"> </p>
<p align="left"> </p>
<div
<div style="width:500px;height:175px;border:1px solid white;">
<p align="left"><font size="6" face="Arial" color="#FFFFFF">Basement Family Room</font> </p><hr>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Tuner" id="Basement Tuner" name="CL1I1O4T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Computer" id="Basement Computer" name="CL1I2O4T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Apple TV" id="Basement Apple TV" name="CL1I3O4T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="iPod" id="Basement iPod" name="CL1I4O4T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
<action="http://192.168.5.30:100" method="POST" >
<font face="Arial">
<input type="submit" value="Off" id="Basement Off" name="DL1O4T" class="auto-style1" style="float: left" /><span class="auto-style1">
</span>
</font>
</form>
</body>
</html>
答案 0 :(得分:0)
1)使用PHP
设置Apache Web服务器2)下载PHP Telnet脚本(或任何其他PHP的Telnet库)
3)修改字符串
if ($this->fp=fsockopen($ip,23)) {
到
if ($this->fp=fsockopen($ip,100)) {
(根据我的理解,您的设备是否响应端口100?)
4)用这样的东西制作PHP脚本(用你的凭证替换username
和password
):
的 proxy.php 强>
<?php
require_once "PHPTelnet.php";
$telnet = new PHPTelnet();
$command = $_GET['command'];
$result = $telnet->Connect('192.168.5.30:100','username','password');
if ($result == 0) {
$telnet->DoCommand($command, $result);
echo $result;
$telnet->Disconnect();
}
?>
5)使HTML页面与此类似(这是非常基本的,只是为了让您了解并用您的网络服务器的IP替换yourhost
):
<html>
<body>
<form action="http://yourhost/proxy.php" method="GET">
Enter command
<input type="text" name="command">
<input type="Submit">
</form>
<form action="http://yourhost/proxy.php" method="GET">
<input type="hidden" value="CL1I3O1T" id="Backyard Apple TV" name="command" />
<input type="Submit" value="Apple TV">
</form>
</body>
</html>
复制HTML文件的最后一部分以添加其他命令。将实际命令放在value
hidden
输入中,并在value
输入的submit
标记。
答案 1 :(得分:0)
我知道这篇文章没有标记PHP,但我终于用PHP套接字解决了这个问题。此网页将响应按下网页按钮,打开到远程IP的套接字,发送一串数据,最后关闭套接字。正如我之前提到的,远程设备是以太网到串行转换器,它连接到音频切换器。我现在可以使用PHP网页控制这个以太网连接/串行控制的音频切换器。代码非常简单,但是语法正确很难。感谢所有帮助过的人!我希望这有助于其他人......以下是代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$input=$_POST['input'];
$sock = fsockopen('192.168.5.30:100', NULL, $errno, $errstr);
fwrite($sock, $input);
echo fread($sock, 4096)."\n";
fclose($sock);
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post">
<input type="submit" name="input" id="button" value="CL1I1O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I2O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I3O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I4O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I5O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I6O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I7O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="CL1I8O1T" />
<br />
<br />
<input type="submit" name="input" id="button" value="DL1O1T" />
<br />
<br />
<form id="form1" name="form1" method="post" action="">
</form>
</body>
</html>