#!/usr/bin/perl 
use warnings;
use strict;

use Socket;
use DBI;
use Date::Parse;
use LWP::Simple;


my $proto = getprotobyname('udp');
my $port = 501; 

my $servaddr = sockaddr_in($port, INADDR_ANY);

socket SERVER, PF_INET, SOCK_DGRAM, $proto or die "Unable to create socket: $!";

bind SERVER, $servaddr or die "Unable to bind: $!";

print "Server running on port $port...\n";


my $message;
my $astr;
my $content;


while (my $client = recv SERVER, $message, 1024, 0) {
    my ($port, $ip) = unpack_sockaddr_in($client);
    my $host = gethostbyaddr($ip, AF_INET);
    print "Client $host:$port sent '$message' at ", scalar(localtime), "\n";
    send SERVER, "Message '$message' received", 0, $client;
    
    
	$astr = $message;
	my $url = "http://localhost/cvs/qms/incoming.php?data=DATA";
	$url =~s/DATA/$astr/g;
		
	print "Content URL: $url \n";
	$content = get($url);
	die "Can't GET $url" if (! defined $content);
	print "Content URL: $content \n";
    
}


