0

我有一个菜鸟问题 - 我创建了一个非常简单的 HTML 页面,当按下按钮时,通过我的网络将一串串行数据发送到以太网到串行转换器。这控制音频矩阵开关(通过其串行端口)。该网页可以工作并且它会切换音频矩阵,但是在我单击一个按钮后,浏览器会无限期地等待响应。我可以单击其他按钮并仍然进行切换,但它总是在等待响应。如何从该远程设备获取响应并在网页上显示(或对其进行操作),并防止页面无限期等待?这是将此数据字符串发送到远程 IP 的正确方法,还是有更好的方法?这是代码:

<html>
<head>
</head>
<body bgcolor="#808080"> 
<div align="center">
&nbsp;<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">&nbsp;</p>
<p align="left">&nbsp;</p>
<p align="left">&nbsp;</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">&nbsp;</p>
<p align="left">&nbsp;</p>
<p align="left">&nbsp;</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">&nbsp;</p>
<p align="left">&nbsp;</p>
<p align="left">&nbsp;</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>
4

2 回答 2

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脚本(替换usernamepassword使用您的凭据): 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页面(这是非常基本的,只是为了给您一些想法并替换yourhost为您的网络服务器的IP):

<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标签放入输入valuesubmit

于 2013-07-20T19:51:50.170 回答
0

I know this post isn't tagged PHP, but I finally got this problem solved with PHP sockets. This web page will respond to a web page button press, open a socket to a remote IP, send a string of data, and finally close the socket. As I mentioned originally, the remote device is an ethernet to serial converter, which is connected to an audio switcher. I can now control this ethernet connected / serial controlled audio switcher using a PHP webpage. The code is pretty simple, but getting the syntax correct was difficult. Thanks to all of those who helped! I hope this helps someone else... Here is the code:

<!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>
于 2013-07-21T03:29:18.800 回答