- 论坛徽章:
- 0
|
您好:
我现在有个SOCKET模拟脚本:
1:#!/usr/bin/perl -w
use Socket;
use IO::Handle;
socket(SOCK,AF_INET,SOCK_STREAM,getprotobyname("tcp"));
setsockopt(SOCK,SOL_SOCKET,SO_REUSEADDR,1);
my $addr=sockaddr_in(3000,INADDR_ANY);
bind(SOCK,$addr);
listen(SOCK,SOMAXCONN);
while(1){
next unless my $addr1=accept(S,SOCK);
S->autoflush(1);
STDOUT->autoflush(1);
# start up simple_invork.pl
#system("perl test1.pl \n");
print S "welcome\n";
while(<S>){
print $_;
chomp;
print S scalar(`$_`)."\n";
}
}
2.#!/usr/bin/perl -w
use Socket;
use IO::Handle;
socket(SOCK,AF_INET,SOCK_STREAM,getprotobyname("tcp"));
my $addr=sockaddr_in(3000,inet_aton("192.168.0.100"));
connect(SOCK,$addr);
SOCK->autoflush(1);
$buff=<SOCK>;
STDOUT->autoflush(1);
print $buff;
while(1){
$in=<STDIN>;
send(SOCK,$in,0);
while(my $l=sysread(SOCK,$buff,9999999)){
print $buff;
last;
}
}
3.
sub main
{
while(my $loc_Line = <STDIN>)
{
chomp $loc_Line;
my $str = test($loc_Line);
syswrite(STDOUT, "[BEGIN]\n");
syswrite(STDOUT, "is ok --$str\n");
syswrite(STDOUT, "[END]\n");
}
}
sub test
{
my $str = shift;
$str = $str.' this is test ! \n';
return $str;
}
main();
请问如何修改脚本实现以下功能:
执行脚本1,2,在脚本2的机器上输入一个'test',通过SOCKET传到脚本1里,
在脚本1中执行脚本3并传入'test'值日,并将脚本3返回的值传给脚本2。
请问改怎么改呢??小弟对网络编程根本不懂。。。 实在不知道改怎么处理了?麻烦大家帮帮忙了 |
|