Thread Socket receive-Frage (35 answers)
Opened by H3llGhost at 2008-06-05 17:32

H3llGhost
 2008-06-07 19:54
#110868 #110868
User since
2007-10-14
60 Artikel
BenutzerIn
[default_avatar]
Dieser Code steht vor der while-Schleife:

Code (perl): (dl )
1
2
3
4
5
6
7
8
        $host_data = (gethostbyname($g_masterserver_address))[4];
        my $address        = join(".", unpack("C4", $host_data));
        my $port           = $g_masterserver_port;
        my $dest           = sockaddr_in($port, inet_aton($address));

        $msg = chr(0xff).chr(0xff)."Z".chr(0xff);
        $bytes = send($::s_socket, $msg, 0, $dest);
        print("$bytes to '$address:$port'");


Und hier noch den Code den ich von php versuche in Perl zu übertragen:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
      $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$packet = chr(255).chr(255)."Z".chr(255);
$bytes_sent = socket_sendto($socket, $packet, strlen($packet), 0, $host, $port);
echo "<b>".$bytes_sent."</b> bytes <b>OK</b></li>";
$recv_bytes = 0;
$buffer = "";
$timeout = 30;
$answer = "";
$packets = 0;
$read = array($socket);
while (socket_select($read, $write = NULL, $except = NULL, &$timeout) > 0) {
$recv_bytes += socket_recvfrom($socket, &$buffer, 2000, 0, &$host, &$port);
if (($buffer[0] == chr(255)) && ($buffer[1] == chr(255)) && ($buffer[2] == "Z") && ($buffer[3] == chr(255)) &&
($buffer[4] == "1") && ($buffer[5] == ".") && ($buffer[6] == "0") && ($buffer[7] == "0") && ($buffer[8] == chr(255))) {
$answer .= substr($buffer, 9, strlen($buffer));
}
$buffer = "";
$timeout = "1";
$packets++;
}

View full thread Socket receive-Frage