手机分类
  导航: 电脑时代在线 · 网站开发 · CgiPerl教程 · CGI应用技巧
有问题吗?看 疑难解答 电脑术语

ecserver.pl 源代码

 
硬件盘点
手机推荐
 
『ecserver.pl 源代码』如果文章有大量图片,显示会较慢,请等待图片下载完成
 
点击数: 更新时间:2005-9-13 


下面的代码有用到unix/linux的系统功能所以不能在NT上使用。
运行这个代码,你需要在相同目录下面放一个文本文件chat.log
聊天内容将保存在这个文件内。代码调用unix/linux处理log的function
写入/读取聊天内容。
至于多进程,好像socket自己就可以处理。。。那个listen()你自己看一下。
Perl我是几乎什么都不懂的。所以只好您老人家自己研究了。:)
搞明白了别忘了教小弟几招。
另外,nt平台上可以用vc写chatserver嘛。(这个我更不懂了)
#!/usr/bin/perl
# EveryChat Server Edition Beta 1
#
# This is beta code. You may not
# upload, post, mirror, share, sell
# or otherwise redistribute this
# code in full or in part without
# written permission from the
# author.
#
# By downloading this code, you
# are granted permission to use
# this code on a single server or
# physical machine provided you
# agree with this license agreement.
#
# This code is provided "AS-IS"
# without any warrantees or
# guarantees of any kind.
#
# This code is protected under US
# and international copyright laws.
#
# (c) 1999 EverySoft
# ALL RIGHTS RESERVED
$servername = 'http://';
$ARGV[0] ||= 'localhost';
$servername .= $ARGV[0];
$ARGV[1] ||= '8080';
$servername .= ":$ARGV[1]";
$ARGV[2] ||= './chat.log';
$ARGV[3] ||= 'EveryChat Server Edition';
$|=1;
use Socket;
use Carp;
use POSIX;
my $proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!";
bind(Server, sockaddr_in($ARGV[1], INADDR_ANY)) || die "bind: $!";
listen(Server,SOMAXCONN) || die "listen: $!";
my $waitedpid = 0;
my $paddr;
$SIG{CHLD} = sub {wait();};
sub checksocket {
my $dummy;
undef $!;
$dummy=<STDIN>;
if (!(defined($dummy)) && !($!)) {
close TAIL;
die("Socket Closed...\n");
}
}
sub spawn {
my $coderef = shift;
my $pid;
if (!defined($pid = fork)) {
print "cannot fork: $!";
return;
} elsif ($pid) {
return; # I'm the parent
}
open(STDIN, "<&Client") || die "can't dup client to stdin";
open(STDOUT, ">&Client") || die "can't dup client to stdout";
exit &$coderef();
}
sub printlines {
open TAIL, "tail -f $ARGV[2] |";
while ($go == 1) {
print "<TABLE BGCOLOR=#EEEEEE CELLSPACING=2 CELLPADDING=3 BORDER=0 WIDTH=100%><TR><TD>" . <TAIL> . "</TD></TR></TABLE><SCRIPT Language=JavaScript1.2><!--\nself.scrollBy(0,640);\n//--></SCRIPT>\n";
&checksocket;
}
close TAIL;
}
sub getform {
$formstring = shift;
foreac

[1] [2] 下一页  


如果您有什么疑问,可以至论坛提出或者解答他人的疑问   返回页面顶部

】【关闭窗口
·上一篇教程:
·下一篇教程:
·导航: 电脑时代在线 · 网站开发 · CgiPerl教程 · CGI应用技巧
相关文章
 
搞笑自拍|图片故事|美女图库|体坛宝贝|明星爆料|世界奇观|风光摄影|历史回忆|大千世界
Photshop超炫图片
advertisement
关于站点 - 广告服务 - 联系我们 - 版权隐私 - 免责声明 - 合作伙伴 - 程序支持 - 网站地图 - 返回顶部  
网站文本地图
  版权所有:电脑时代在线 2005-2007 欢迎各种媒体转载我们的原创作品[转载请注明出处]
copyright © 2005-2007 www.PCvz.com online services. all rights reserved. 蜀ICP备05015578
Template designed by LaoJiang. Optimized for 1024x768 to Firefox,Opera and MS-IE. Site powered by EQL.
红盾
热爱电脑,热爱生活
拥有电脑,拥有生命
让我们享受拥有电脑的时光