Chinaunix
标题:
socket双向通信中接受返回数据的问题
[打印本页]
作者:
猪鼻插葱
时间:
2010-09-26 10:30
标题:
socket双向通信中接受返回数据的问题
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $port, $handle);
unless (@ARGV == 2) { die "usage: $0 host port" };
($host, $port) = @ARGV;
my $type=SOCK_STREAM;
# create a tcp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => $host,
PeerPort => $port,
Type=>$type
)
or die "can't connect to port $port on $host: $!";
die "SOCKET creat error:$!" unless $handle;
open(MYFILE,"mail.txt")or die "can't open file:$!";\
seek (MYFILE,0,0);
while(<MYFILE>)
{
print $handle $_ or die "Send message error:$!";
}
print $handle "\0";
close ($handle);
复制代码
上面是我写的一个client,我尝试通过这个套接字接受返回的数据,我使用了accept去接受数据,不过没有什么反应,哪位熟悉这个的希望指点一下小弟,不胜感激。
作者:
Mr-Summer
时间:
2010-09-26 17:42
要不把accept的语句也贴出来吧。
有些时候不传“\n”,就会等不到sever端的输出。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2