Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No response to socket

Status
Not open for further replies.

chals1

Technical User
Sep 3, 2003
73
ES
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>
 
What's going now?
Did you mean?
name="$_POST['message']"

That error didn't ocurred a while ago!!
 
Code:
echo ("Enviando el msg ");
echo $_POST['message'];
fputs ($fp, $_POST['message']);

That's what I mean.
 
It already works
Xport needs the last character of the command to be
either a carriage return or a line feed
After
Code:
fputs ($fp, $_POST['message']);

i've added
Code:
fputs ($fp, "\r")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top