#!/usr/bin/perl use IO::Socket; my $sock = &rdt_connect($ARGV[0],$ARGV[1]); $msg = "get $ARGV[2]"; $sendmsg = &rdt_send($msg); print length($sendmsg); &sendall($sock,$sendmsg); sub rdt_connect { #takes necessary parameters, creates socket and connects to that client. my ($serverconnect,$portconnect) = @_; $proto = 'udp'; $socket = IO::Socket::INET->new (PeerAddr=>$_[0],PeerPort=>$_[1],Proto=>'udp') or die "Can't Connect $!"; return $socket; } sub rdt_send{ #makes packet and sends it to the socket. my $datatosend = @_; $lengthpayload = length($_[0]); $r = 'R';$d='D';$t='T';$one=1;$point = '.';$zero=0;$null1=00000000;$null2=00000000;$null3=00000000;$null4=00000000;$null5=00000000;$null6=00000000;$null7=00000000; $protocol = pack("a"x6,$r,$d,$t,$one,$point,$zero); $packetheader = pack('N3 n N3 n',$null1,$null2,$null3,$lengthpayload,$null4,$null5,$null6,$null7); #$packetpayload = $packetheader.$datatosend; $packetpayload = pack('a*',$_[0]); $tobuffer = ($protocol.$packetheader.$packetpayload); return $tobuffer; } sub sendall{ my ($socket,$packet) = @_; if ($packet ne ''){$_[0]->send($_[1]) or die "Send error: $!\n";} }