Chinaunix

标题: socket双向通信中接受返回数据的问题 [打印本页]

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




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2