He can connect
He can receive result is : Resource id #68
but couldnt write error :Insim : first byte in Packet does not match size
Please helpme
Can you send me a php example for Insim in php for Insim version 4
It is a LFS Z28 Server
Thanks
<?php
// CONFIG START
$insimIP = '192.168.128.119'; // Your InSim-IP Here
$insimPort = 29999; // Your InSim-Port
$adminPW = 'password'; // Your Admin-Password
// CONFIG END
// create sender filestream
$errno = 0; $errstr = "";
$sender = @fsockopen("udp://$insimIP", $insimPort, &$errno, &$errstr, 3);
if (!$sender) {
die("Error:\nCould not connect to $insimIP:$insimPort\n"
. "Error Number: $errno\nError Description: $errstr");
}
// create receiver filestream
$localport = 63392;
$receiver = false;
while ($localport <= 65535) {
$receiver = @stream_socket_server("udp://192.168.128.119:$localport", $errno, $errstr, STREAM_SERVER_BIND);
if (is_resource($receiver)) {
break;
}
$localport++;
$receiver = false;
}
if ($receiver === false) {
die("Error:\nCould not bind to $localport\nError Number: $errno\nError Description: $errstr");
}
// Make the receiver stream nonblocking to be able to apply timeouts
stream_set_blocking($receiver, 0);
/*
VARIABLES AFTER HERE:
$sender : sender filestream
$receiver : receiver filestream
$localport : port of receiver filestream
+ config variables
*/
// We will now have to send an ISI (InSimInit)-packet to InSim to make it accept our requests.
// Prepare packet
$packet = "";
$packet .= "ISI\1"; // Packet-ID
$packet .= pack("S", $localport); // response port
$packet .= pack("c", 2+4+32); // Connection Flags - see InSim.txt
$packet .= pack("c", 1); // NodeSecs - time between packages
if (strlen($adminPW) > 16) {
$adminPW = substr($adminPW, 0, 16); // Cut down adminpw if too long
}
$packet .= str_pad($adminPW, 16, "\0"); // Admin-Password if set in LFS host options
// Send packet
fwrite($sender, $packet, strlen($packet)); // Third parameter to make PHP ignore magic_quotes-setting
$content = $receiver;
?>