Hi,
I have got the following script which connects to a server program that I have scripted in c++. I want the php script to send commands to the program and it is doing that. However I dont think the php is sending the data correctly as although the server says it has recieved the data it is not proccessing it correctly. I know this is not the server itself as I can connect to it via telnet and it when I send the command it all works properly. So is their either a more specific way of connecting to telnet in php or is there something that I need to change in my php code?
<?php
$server = "127.0.0.1";
$port = "20248";
$data = "STOP";
$connection = fsockopen($server, $port, $errno, $errstr, 30);
if(!$connection) {
print "Connect Failed: $errstr ($errno)";
} else {
$output = fgets($connection, 20248);
fputs($connection, "$data\n");
}
?>