Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1467807
  • 博文数量: 139
  • 博客积分: 10005
  • 博客等级: 中将
  • 技术积分: 4740
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-01 14:39
文章分类

全部博文(139)

文章存档

2010年(63)

2009年(27)

2008年(49)

我的朋友

分类:

2009-07-23 13:57:43

#!/usr/bin/perl -w
use IO::Socket;
$ip_addr = '210.75.27.29';
$u_port = 5555 ;
$sock_1 = IO::Socket::INET->new(
    LocalHost => $ip_addr,
    LocalPort => $u_port,
    Proto => 'tcp',
    Listen => 20,
    Reuse => 1,
)
or die "no socket:$!";
while ( 1 )
{
    $sock_2 = $sock_1->accept() or die "accept socket error:$!";;
    while( $data = <$sock_2> )
    {
        print $data;
        if ( $data =~ /run:/ )
        {
            $my_command = $data;
            $my_command =~ s/run:/ / ;
            system ($my_command);
        }


        if ( $data =~ /exit/ )
        {
            $retval = fork();
            if ($retval == 0)
            {
                close $sock_2;
                close $sock_1;
                exit;
                # this is the parent process
            }
            else
            {
                print "retval:",$retval,"\n";
                close $sock_2;
                last;
                # this terminates the child process
            }
        }
    }
}

阅读(1038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~