I have this code to get a temperature message from a server connected into a temperature sensor, but there isn't any response
Code:
<html>
<head>
<style type="text/css">
input {
background-color: #000000;
color: #ffffff;
}
#box1{
position: absolute;
width: 250px;
border: solid #000000 3px;
background-color: #ffffff;
color: #000000;
padding: 10px;
}
</style>
</head>
<body>
<?
// form not yet submitted
if (!$submit)
{
?>
<div id="box1">
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<b>Sensor de temperatura</b><br>
<input type="Text" name="message" size="15"><input type="submit"
name="submit" value="Enviar">
</form>
</div>
<?
}
else
{
// form submitted
// where is the socket server?
$host="158.42.58.43";
$port = 10001;
// open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp)
{
$result = "Error: could not open socket connection";
}
else
{
// get the welcome message
fgets ($fp, 1024);
// write the user string to the socket
fputs ($fp, $message);
// get the result
$result .= fgets ($fp, 1024);
// close the connection
fputs ($fp, "END");
fclose ($fp);
// trim the result and remove the starting ?
$result = trim($result);
$result = substr($result, 2);
// now print it to the browser
}
?>
Server said: <b><? echo $result; ?></b>
<?
}
?>
</body>
</html>