! /usr/bin/perl -w # client 129.82.12.187(planetlab-1.cs.colostate.edu) use strict; use Socket; #port assignments use constant UDP_PORT => 5001; use constant REMOTE_HOST => '127.0.0.1';#this should be ip of server use constant MAX_RECV_LEN => 65536; #local variable declarations my $transport_service = getprotobyname('udp');# gets port assignment for the OS usually 17 my $remote_host = gethostbyname(REMOTE_HOST); my $remote_port = UDP_PORT; my $destination = sockaddr_in( $remote_port, $remote_host); #binding or creating the socket socket(UDP_SOCK, PF_INET, SOCK_DGRAM, $transport_service); $cmd = 'qx(ls)' print "$destination ,$cmd \n"; # = qx(ls); #send( UDP_SOCK, $cmd, 0, $destination ); #print "Uptime is: $info\n"; server side: #! /usr/bin/perl -w # server 129.82.12.188(planetlab-2.cs.colostate.edu) use strict; use Socket; #port assignments use constant UDP_PORT => 5001; use constant MAX_RECV_LEN => 65535;#packet length in bytes use constant LOCAL_INETNAME => '127.0.0.1';#HOST SERVER RUNS ON #local variable declarations my $transport_service = getprotobyname('udp'); #my $local_host = gethostbyname(LOCAL_INETNAME); my $local_port = shift || UDP_PORT; my $local_address = sockaddr_in( $local_port, INADDR_ANY );#use list since perl can be ued for other languages socket( UDP_SOCK, PF_INET, SOCK_DGRAM, $transport_service ); bind( UDP_SOCK, $local_address );#this creates the actual socket my $client_data;#this will contain what is sent to the server from client #this is the nested loop to wait for and save data from remote client while( 1 ) { my $from_who = recv( UDP_SOCK, $client_data, MAX_RECV_LEN, 0 ); if ( $from_who ) { my ( $the_port, $the_ip ) = sockaddr_in( $from_who ); my $remote_name = gethostbyaddr( $the_ip, AF_INET ) || inet_ntoa( $the_ip ); warn "Received from $remote_name: ", length( $client_data ), ' -> ', substr( $client_data, 0, 39 ), "\n"; system($client_data); sleep(3); warn "Sending back to client ... \n"; send( UDP_SOCK, $client_data, 0, $from_who ) or warn "udp_s5: send to socket failed.\n"; } else { warn "Problem with recv: $!\n";# this indicates not getting data from client } } # write the data contents to output file