Jet direct control page
";
* print_r($_POST);
* echo "";
*}
*/
//generate user input form
?>
Messages:
if(isset($_POST['Submit'])) //check if user submitted form
{
//if user has submited data
// The raw port number for the print server
$service_port = $_POST['port'];
// The network address of the print server
// This can be an ip address or a network name
$address = gethostbyname($_POST['ip']);
echo " ";
echo "Creating socket...";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //create the socket or fail
if ($socket === false) {
echo "
socket_create() failed: reason: " .
socket_strerror(socket_last_error()) . "\n";
die();
} else {
echo "OK.
";
}
echo "Connecting to print server: " . $address . "...";
$result = socket_connect($socket, $address, $service_port); //connect to the print server
if ($result === false) {
echo "
socket_connect() failed.\nReason: ($result) " .
socket_strerror(socket_last_error($socket)) . "\n";
die();
} else {
echo "OK.
";
}
$out=0;
//check to see if which boxes have been checked and add thier bit value to $out
// bit num: 8 7 6 5 4 3 2 1
// value: 128 64 32 16 8 4 2 1
//if(isset($_POST['resetall']){
// $out = 0;
//}
//else{
if(isset($_POST['bit8'])) {
$out +=1;
}
if(isset($_POST['bit7'])) {
$out += 2;
}
if(isset($_POST['bit6'])) {
$out += 4;
}
if(isset($_POST['bit5'])) {
$out += 8;
}
if(isset($_POST['bit4'])) {
$out +=16;
}
if(isset($_POST['bit3'])) {
$out += 32;
}
if(isset($_POST['bit2'])) {
$out += 64;
}
if(isset($_POST['bit1'])) {
$out += 128;
//}
}
if(isset($_POST['resetall'])){
$out = 0;
}
echo "Sending to print server...
";
// since php does not have byte type varables and wants to send ascii over sockets
// we use chr($out) to send the char with the matching value of the value we want to send
socket_write($socket, chr($out), strlen(chr($out)));
socket_close($socket); // close the socket
echo "Sent!
";
}
?>