in reply to Translating Socket to IO::Socket;

This kind of translation is usually very straight forward, I commented out some original code, and added mine immediately after.

I didn't test the code, and guess you may have a peer to test against. There might be mistakes, but you can certainly come back and discuss.

sub q3msg { my ($host, $port, $timeout, $msg) = @_; my $iaddr = gethostbyname(hostname()); my $sin = sockaddr_in(0, $iaddr); =document socket(SOCK, PF_INET, SOCK_DGRAM, getprotobyname('udp')) or die "s +ocket: $!\n"; bind(SOCK, $sin) or die "bind: $!\n"; =cut my $sock = new IO::Socket::INET(Proto => "udp", LocalAddr => $iadd +r, LocalPort => 0) or die "failed to create UDP socket"; my $hisaddr = inet_aton($host) or die "unknown host \"$host\"\n"; my $srvaddr = sockaddr_in($port, $hisaddr); #defined(send(SOCK, chr(255) x 4 . $msg, 0, $srvaddr)) or die "sen +d: $!\n"; defined(send($sock, chr(255) x 4 . $msg, 0, $srvaddr)) or die "sen +d: $!\n"; my ($rin, $rout); $rin = ""; vec($rin, fileno(SOCK), 1) = 1; if (select($rout=$rin, undef, undef, $timeout)) { #recv(SOCK, $_, 65507, 0) or die "recv: $!\n"; recv($sock, $_, 65507, 0) or die "recv: $!\n"; s/\033.//g; my @response = split /^/m; shift @response; return \@response; } else { return undef; } }

Update:

Actually you can take a look at those two nodes of mine: An internet garbage filter and My experience with Perl threading and the reason I think that I have rushed a little bit. The two pieces of code do the same thing, but the first one is threaded and uses raw socket, and the second one is not threaded and uses IO::Socket. By comparing those two pieces, you can get a good idea of the translation you wanted.

By looking at the title of your post, I saw you compared IO::Socket with "Socket", instead of "socket". I guess (100% pure guess, my guess could be totally wrong) that, you might thought socket is defined in module Socket. That is not true. Raw socket is not defined as object. Module Socket does not give any socket implementation, indeed it just defines a bunch of helper methods, such as inet_atoi etc., also a set of socket related constants.