perl网络编程中关于接受数据的疑惑,该如何处理
发布时间:2011-06-29 20:03:56 文章来源:www.iduyao.cn 采编人员:星星草
perl网络编程中关于接受数据的疑惑
接受了一个套接字的连接以后,为什么传入的数据读不出来??代码如下:
use strict;
use IO::Socket;
use IO::Handle;
use constant MY_PORT => 12007;
#构建Socket套接字
my $port = MY_PORT;
my $sock = IO::Socket::INET-> new(Listen => 20,
LocalPort => $port,
Timeout => 60*60,
Reuse => 1)
or die "Cannot create Listening socket: $!\n ";
while(1)
{
next unless my $session = $sock-> accept;
my $peer = gethostbyaddr($session-> peeraddr, AF_INET) ||
$session-> peerhost;
my $port = $session-> peerport;
print $port, "\n ";
print $peer, "\n ";
print <$session> ;
close $session;
}
close $sock;
打印了一下$!诊断了一下,说是Bad file descriptor
客户端是用C 语言写的,代码也贴上来吧
#include "stdafx.h "
#include "winsock2.h "
#include <malloc.h>
#define USERPORT 12007
#define MAJOR_VERSION 1
#define MINOR_VERSION 2
#define WSA_MAKEWORD(x,y) ((y)*256+(x))
int main(int argc, char* argv[])
{
char buf[1024];
// struct sockaddr_in client;
struct sockaddr_in server;
struct hostent FAR * host;
int Status;
SOCKET s;
int ns;
int namelen;
WORD wMajorVersion, wMinorVersion;
LPWSADATA lpmyWSAData;
WORD VersionReqd;
wMajorVersion = MAJOR_VERSION;
wMinorVersion = MINOR_VERSION;
VersionReqd = WSA_MAKEWORD(wMajorVersion,wMinorVersion);
lpmyWSAData = (LPWSADATA)malloc(sizeof(WSADATA));
Status = WSAStartup(VersionReqd, lpmyWSAData);
if ((s=socket(AF_INET, SOCK_STREAM, 0)) <0)
{
printf( "Socket() ");
return -1;
}
host = gethostbyname( "Yinth ");
if (host == NULL)
{
printf( "No host machine ");
return -1;
}
ZeroMemory(&server, sizeof(server));
memset(&server, '\0 ', sizeof (struct sockaddr_in));
memcpy((char FAR *)&server.sin_addr,(char FAR *)host-> h_addr,host-> h_length);
server.sin_family = host-> h_addrtype;
server.sin_port = htons(USERPORT);
printf( "请输入: ");
char str[256];
gets(str);
connect(s, (struct sockaddr FAR *)&server, sizeof(server));
int i = send(s, str, sizeof(str),MSG_OOB);
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
能不能找到支持 python 2.6 2.7 3.x 版本的 mod_python 呢?
http://archive.apache.org/dist/httpd/modpython/win/3.3.1/
我在...
-
windows下安装apache + python + django + mod_wsgi.so
对应版本:
Apache:Apache HTTP Server (httpd) 2.2.19
Python:Python2.7
Dja...
-
手工执行python3程序没问题,放在cron里面就不执行有中文的代码,高手帮忙啊。急!
先介绍下基本情况
环境: redhat Python3.2
目的:定...
-
PYTHON用什么编辑器?
是用自带的IDLE不?
------解决方案--------------------
看下国外的Python用户都用什么吧:
http://jobs.pyth...
-
为什么在python25中输入下面的代码是错误的??求大神!
if 1 < 0:
print '”x” must be atleast 0!'
------解决方案-----...
-
pyhthon zipfile获取压缩文件列表后怎样打开其中某个文件?
如题。似乎ZipFile没有open操作..
zCmfile = zipfile.ZipFile(target...
-
本人菜鸟一个,哪位大神帮我解释一下下面两段
import sys
print >> sys.stderr, 'Fatal error: invalid input!'
import sys
...
-
老王的python学习网站!推荐!
http://blog.csdn.net/hendom/article/details/7173207
很不错的python学习网站。
http://www.cnpyt...
-
myeclipse里导入python项目
初学python,我在myeclipse里导入已有项目,选择路径后为什么没出现该项目,这项目不应该有问题啊,我用的是m...
-
安装PyQt的问题?
今天在ubuntu下安装了PyQt-x11-gpl-4.9,但是我按照《getting started with PyQt》上的一个例子
import sys
from ...