- 论坛徽章:
- 0
|
- # cat so.pl
- #!/usr/bin/perl
- use strict;
- use IO::Socket::INET;
- my $sock = IO::Socket::INET->new(
- Protp => 'tcp',
- LocalPort => '7890',
- Type => SOCK_STREAM,
- Listen => '10',
- Reuse => '1',
- Timeout => '5',
- );
- if (not defined $sock) {
- print "socket error!\n";
- exit(1);
- }
- while(1) {
- my $buf = "";
- my $c;
- my $ret = 0;
- if (accept($c, $sock)){
- $ret = read($c, $buf, 4);
- #if $ret ....
- if ($buf =~ /^cmds/){
- print "I got cmds, I can do expect cmds here\n";
- }
- elsif ($buf =~ /^quit/){
- print "I got quit, I can send quit to expect here\n";
- }
- }
- }
复制代码
# perl so.pl
I got quit, I can send quit to expect here
I got cmds, I can do expect cmds here
I got quit, I can send quit to expect here
其他的你自己加吧,而且这个代码也不完善 |
|