Leser: 6
|< 1 2 3 4 >| | 36 Einträge, 4 Seiten |
1 2 3 4 5 6 7
if(IO::Select->new($s_socket)->can_read(10)) { # 2 second timeout $s_socket->recv($s_output, 1024); $timeout = 0; print $s_output; } else { $timeout++; }
1
2
3
4
5
my $buffer = '';
while (my $rc = $s_socket->recv($s_output, 1024) ) {
$buffer .= $s_output;
}
# und dann weitere Verarbeitung
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
while ($timeout % 60 == 0) { print "hier"; if(IO::Select->new($s_socket)->can_read(2)) { # 2 second timeout while (my $rc = $s_socket->recv($s_output, 1024) ) { $buffer .= $s_output; } print $buffer; $timeout = 0; # $s_socket->recv($s_output, 1024); # $timeout = 0; # print $s_output; } else { $timeout++; } print $timeout; }
my $s_socket = IO::Select->new($s_socket);
1 2 3 4
$s_socket = IO::Socket::INET->new( Proto=>"udp", LocalAddr=>"$s_ip", LocalPort=>"$s_port");
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
if ($s_ip) { $ip = $s_ip . ":"; } else { $ip = "port "; } my $s_socket = IO::Socket::INET->new( Proto=>"udp", LocalAddr=>"$s_ip", LocalPort=>"$s_port" ) or die ("\nCan't setup UDP socket on $ip:$s_port $!\n"); print("Opening UDP listen socket on $ip$s_port ... ok\n"); while ($timeout % 60 == 0) { print "hier"; if(IO::Select->new($s_socket)->can_read(2)) { # 2 second timeout while (my $rc = $s_socket->recv($s_output, 1024) ) { $buffer .= $s_output; } print $buffer; $timeout = 0; # $s_socket->recv($s_output, 1024); # print $s_output; } else { $timeout++; } print $timeout; }
H3llGhost+2008-06-07 17:22:00--Doch leider funktioniert das nicht ...
Hat jemand eine Idee, wie warum das bei mir nicht geht ...
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'");
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++;
}
|< 1 2 3 4 >| | 36 Einträge, 4 Seiten |