dantheman1210 has asked for the wisdom of the Perl Monks concerning the following question:
OK long story short I have a UDP listener using IO::Socket::INET that I am trying to grab the first 4 bytes from the data with a pattern match that is failing on roughly 1 out of 100 packets. First here is my simplified code:
#!/usr/bin/perl -w $|++; use strict; use IO::Socket; use IO::Select; my $response = IO::Socket::INET->new(Proto=>"udp",LocalPort=>5000) or die "Can't make UDP server: $@"; my $sel = new IO::Select( $response ); my ($datagram,$flags); binmode($response); while(my @ready = $sel->can_read) #Make sure socket has something to g +ive us { $datagram = ''; $flags = ''; $response->recv($datagram,1500,$flags); my $length = length($datagram); print "Length : $length\n"; if($datagram =~ /^(\C\C\C\C)(.*)$/s) { #Do some stuff } else { #Didn't match for some reason print "Did not match!\n"; } }
Here is the root of my question: I print out the length of the packet just prior to attempting the pattern match, which always has a length of "1205", but when I attempt the match with $datagram =~ /^(\C\C\C\C)(.*)$/s it sometimes fails. How can this match fail (which I believe is just looking for the first 4 bytes in the datagram) when the data is 1205 bytes long?
Oh, and here is a snipet of the output:
Length : 1205 Length : 1205 Length : 1205 Length : 1205 Length : 1205 Did not match! Length : 1205 Length : 1205
Any guidance would be greatly appreciated! :)
|
|---|