#!/usr/local/bin/perl use Tk; use IO::Socket; use Net::Address::IP::Local; use Sys::Hostname; use Socket; use Socket; use IO::Socket::INET; my $address = Net::Address::IP::Local->public; my($ipaddr)=inet_ntoa((gethostbyname(hostname))[4]); $local = IO::Socket::INET->new( Proto => 'tcp', LocalAddr => "$ipaddr:8087", ) or die "$!"; $local->listen(); $local->autoflush(1); my $addr; #Not sure why I have this while ($addr = $local->accept() ) { print "Connection from: ", $addr->peerhost(),"\n"; print "Ready for command.\n\n"; $path = "C:/Program Files (x86)/Common Files/X10/Common"; chdir($path) or die "Cant chdir to $path $!"; #Don't know what this does ~s/GET//g,~s/~/ /g,~s/%20/ /g,~s/%22/ /g,~s/x10command=DEVICE//g, ~s/\//\ /g,~s/[?]//g ,~s/'/ /g,~s/HTTP/ /g,~s/1.1/ /g; system(AHCMD. "$_"); my $mw = new MainWindow; my $frm_name = $mw -> Frame() -> pack(); my $lab = $frm_name -> Label(-text=>"Your IP is $address Port 8087") -> pack(); my $but = $mw -> Button(-text=>"Launch Server", -command =>\&push_button) -> pack(); my $txt = $mw -> Text(-width=>40, -height=>25) -> pack(); #Needs to be multi line. MainLoop; sub push_button { #Rather than push button, I need the client to trigger this @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); $year = 1900 + $yearOffset; $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year"; $txt -> insert('end', "Connection From: " ); $txt -> insert('end', $addr->peerhost() ); $txt -> insert('end', "\n" ); $txt -> insert('end', "$theTime \n" ); $txt -> insert('end',"Received: $_"); #The text that was received print "Received: $_ \n"; print $addr $_; #print $path $_; #close $addr; chomp; #Not sure what this does print "Ready for next command....\n\n"; #Really don't need this and don't want the black box showing . close $addr; # close client } }