Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226529
  • 博文数量: 50
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 541
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-03 11:48
文章分类

全部博文(50)

文章存档

2010年(38)

2009年(12)

我的朋友

分类:

2010-07-13 22:27:15

服务端如下:

#!/usr/bin/perl -w


use strict;
use IO::Socket;

my $server_port = 9999;
my $client;

my $server = IO::Socket::INET->new(LocalPort => $server_port,
                                   Type => SOCK_STREAM,
                                   Reuse => 1,
                                   Listen => 10) or die "Couldn't be a tcp server on port $server_port: $!\n";
  
#while ( $client = $server->accept())


my $newSocket = $server->accept();

while (<$newSocket>)
{
        print $_;
        #$server->send("55555555555555\n");

}



close($server);

 

 

客户端如下:


 

#!/usr/bin/perl -w


use strict;
use IO::Socket;

my $remote_host = '127.0.0.1';
my $remote_port = 9999;

my $socket = IO::Socket::INET->new(PeerAddr => $remote_host,
                                   PeerPort => $remote_port,
                                   Proto => "tcp",
                                   Type => SOCK_STREAM ) or die "Couldn't connect to $remote_host, $remote_port: $!\n";

print "$socket,\t I'm is client\n";


print $socket "sucess \n";
print $socket "sucess \n";

my $answer = <$socket>;
#my $newSocket = $socket->accept();


close($socket);


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