D
deadpickle
What I want to do is create an interface using Tk. What I have so far
is:
use Tk;
use Tk::LabEntry;
use IO::Socket;
#Main window interface
my $mainwindow = new MainWindow;
my $left = $mainwindow->Frame->grid(-row => 1,
-column => 0,
-sticky => 'nw');
my $bottom = $mainwindow->Frame->grid(-row => 2,
-column => 0,
-columnspan => 3,
-sticky => 'nw');
$left->LabEntry(-label => "PORT",
-labelPack => [-side => "left", -anchor => "w" ],
-textvariable => \$port->{PORT},
-width => 5,
)->pack;
MainLoop;
The program this is for sets up a server that listens for a client to
connect. I have a few questions:
1. How do I set this up so that 'use strict' will work?
2. I want to be able to enter a value into the "PORT" widget that is
then stored in the variable $port, am I doing this correctly?
3. I want to create a text box at the bottm that will echo what port is
being used and whether or not a client has connected, any hints on how
to do this would be valueble?
4. When it is ready I want to be able to hit a button on the bottom
that runs the script until the button is hit again, then the script
stops. Here is the script I want to run:
my $sock = new IO::Socket::INET(
LocalPort => $port,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
$|=1;
my($new_sock, $c_addr, $buf);
while (($new_sock, $c_addr) = $sock->accept()) {
my ($client_port, $c_ip) = sockaddr_in($c_addr);
my $client_ipnum = inet_ntoa($c_ip);
my $client_host = gethostbyaddr($c_ip, AF_INET);
print "got a connection from: $client_host","
[$client_ipnum]\n";
while (defined ($buf = <$new_sock>)) {
chomp($buf);
if ($buf=~/^FILE\|/){
my $filename = (split /\|/, $buf)[1];
unless (open (FH, "<", $filename)){
print $new_sock "NACK|File '$filename'
do not exists\n";
}
else {
while (my $line =<FH>){
chomp($line);
print $new_sock
"FIL|".$line."\n";
#
# Remove/comment next line in
production
#
print "SENT>FIL|".$line."\n";
}
close(FH);
print $new_sock "EOT|\n";
}
last;
}
elsif ($buf=~/^QUIT\|/){
last;
}
else {
print $new_sock "NACK|Command not
understood\n";
last;
}
}
close($new_sock);
}
exit;
Any help is appreciated. Thanks.
is:
use Tk;
use Tk::LabEntry;
use IO::Socket;
#Main window interface
my $mainwindow = new MainWindow;
my $left = $mainwindow->Frame->grid(-row => 1,
-column => 0,
-sticky => 'nw');
my $bottom = $mainwindow->Frame->grid(-row => 2,
-column => 0,
-columnspan => 3,
-sticky => 'nw');
$left->LabEntry(-label => "PORT",
-labelPack => [-side => "left", -anchor => "w" ],
-textvariable => \$port->{PORT},
-width => 5,
)->pack;
MainLoop;
The program this is for sets up a server that listens for a client to
connect. I have a few questions:
1. How do I set this up so that 'use strict' will work?
2. I want to be able to enter a value into the "PORT" widget that is
then stored in the variable $port, am I doing this correctly?
3. I want to create a text box at the bottm that will echo what port is
being used and whether or not a client has connected, any hints on how
to do this would be valueble?
4. When it is ready I want to be able to hit a button on the bottom
that runs the script until the button is hit again, then the script
stops. Here is the script I want to run:
my $sock = new IO::Socket::INET(
LocalPort => $port,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
$|=1;
my($new_sock, $c_addr, $buf);
while (($new_sock, $c_addr) = $sock->accept()) {
my ($client_port, $c_ip) = sockaddr_in($c_addr);
my $client_ipnum = inet_ntoa($c_ip);
my $client_host = gethostbyaddr($c_ip, AF_INET);
print "got a connection from: $client_host","
[$client_ipnum]\n";
while (defined ($buf = <$new_sock>)) {
chomp($buf);
if ($buf=~/^FILE\|/){
my $filename = (split /\|/, $buf)[1];
unless (open (FH, "<", $filename)){
print $new_sock "NACK|File '$filename'
do not exists\n";
}
else {
while (my $line =<FH>){
chomp($line);
print $new_sock
"FIL|".$line."\n";
#
# Remove/comment next line in
production
#
print "SENT>FIL|".$line."\n";
}
close(FH);
print $new_sock "EOT|\n";
}
last;
}
elsif ($buf=~/^QUIT\|/){
last;
}
else {
print $new_sock "NACK|Command not
understood\n";
last;
}
}
close($new_sock);
}
exit;
Any help is appreciated. Thanks.