Hi i have written a server prog.....
which listens to client and echo's back....
if i type "Run" in the client........i want the server
to execute a program "run.pl" in the background...
(that is the server should not wait for the completion
of the program)
if i type "RunProg" in the client........i want the
server to execute a program "runprog.pl"
(in this case it needs to wait untill the prog
completes).
CODE :-
-----------
use IO::Select;
use IO::Socket;
$lsn = new IO::Socket::INET(Listen => 1, LocalPort
=> 8080);
$sel = new IO::Select( $lsn );
while(@ready = $sel->can_read) {
foreach $fh (@ready) {
if($fh == $lsn) {
# Create a new socket
$new = $lsn->accept;
$sel->add($new);
$message = "Request User... $new \n";
print $message."\n";
sendall($message,$new);
}
else {
# Process socket
$msg =getmsg($fh);
print ">From $fh : $msg \n";
# Maybe we have finished with the socket
if ($msg eq "quit")
{
sendall("Closing ..",$fh);
$sel->remove($fh);
$fh->close;
}
elsif ($msg eq "run")
{
print "Running a process \n";
#######Need to find ...
}
elsif ($msg eq "runprog")
{
print "Running a process \n";
#######Need to find ...
}
else
{
$msg= "Server :".$msg."\n";
sendall($msg,$fh);
}
}
}
}
sub sendall
{
my $msg = shift;
my $wfh = shift;
foreach($sel->can_write)
{
if ($_ eq $wfh)
{
syswrite($wfh, ":".$msg.":", length($msg))
}
}
}
sub getmsg
{
my ($handle) = @_;
my $msg = "";
my $in = "";
do {
$msg .= $in;
$nread = sysread($handle, $in, 1024);
} while ($nread == 1);
return($msg);
}
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger.
http://im.yahoo.com
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin