Page 1 of 1

getting some zone info using php

Posted: 05 Oct 2006, 10:11
by dream
hello Lapo,
I used a simple php script to connect to the sfs. I create the socket, then connect to the server, then I send some data.. but I don't get the response

here is the small script.. I used bold on the areas that might present a problem.

<?
$ip = '216.xxx.xxx.xx';
$port = 'xxxx';

/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) echo "socket_create() failed: reason: " , socket_strerror($socket) , "\n";
else echo "OK.\n";

$result = socket_connect($socket, $ip, $port);
if ($result < 0) echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
else echo "OK.\n";

$in = "<msg t='sys'><body action='verChk' r='0'><ver v='102' /></body></msg>";
$out = '';

socket_write($socket, $in, strlen($in));

while ($out = socket_read($socket, 2048)) {
echo $out;
}

socket_close($socket);
?>

Posted: 05 Oct 2006, 10:43
by Lapo
All messages from client to server and vice versa follow the Flash XMLSocket() object format, which puts a 0x00 byte at the end of the string.

Just add a byte 0 to the end of your messages and it should work

Posted: 05 Oct 2006, 13:20
by dream
i can't seem to get it to work.. I tried both the "\0" char and "\x00" in php..
do you have an article on general php clients trying to emulate the flash xml send function? I have searched but did not find anything valuable...

I connected also via telnet just for fun but was not able to send a message because I don;t know how to send the 0x00 character in the end

Posted: 06 Oct 2006, 07:32
by Lapo
do you have an article on general php clients trying to emulate the flash xml send function?
No, we don't have articles about PHP connectin' to SFS.
However PHP has a rich set of functions, I'd recommend to check the online documentation (www.php.net) or download the manual and look for examples under the "Socket" section or the "String" section.

You probably need a String function that adds a 0x00 byte to the end of your string or to the socket byte stream.

Posted: 12 Oct 2006, 08:58
by dream
has anyone done this successfuly? if so, please tell me.. post it here.. any php code that connects to the server and exchanges info would be greatly appreciated. Thank you.