您的位置:首页 >> Web开发 >> CGI技术 >> 正文
CGI技术 RSS
 

ecserver.pl 源代码

http://www.rdxx.com 06年04月21日 07:47 网海之贝 我要投稿

关键词: 源代码
下面的代码有用到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";
共4页  1 2 3 4

 
 
标签: 源代码 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站