Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsOk, PERL gurus! I am working on a project to allow streaming(scrolling) text for a cgi chat server in a
multi-framed HTML document. I have seen several client / server models and sample code, but cannot seem to get it straight. The problem I see with many of the
sample daemons is that they create way too much server
load. ex. The have to spawn a child process to
communicate with a newly opened socket. I need a
server to accept incoming sockets and to print messages
recieved from a socket to all other open connections
from ONE process(I guess this would be similar to the
innd process). I will be INCREDIBLY grateful for some
advice as this is an extremely important feature for me to
add. Thank you very much.
------ Text Omitted .... Code needing fixed is listed below
I feel the code is almost there, but it has bugs in it. I've set the server to listen on a particular port. Rather then writing the client, I've just telneted in to test the
response. Once the socket is opened, I type in data(then of course the steam will be ended via a \n) and the data is sent back to my socket and it is then closed. For some
reason the text is not being broadcasted to other open connections. I'd really appreciate further help if it is possible. Also, once completed this version should be
able to support up to and even beyond 50 - 100 simultaneous users. Is this feasable with this implementation. Here is my code so far. Also The cgi web-based interface will be in a
3 frame window. The upper left frame will recieve all new
text written by other chatters. The lower frame will allow the user to add new text, which will in turn be sent to the upper right frame. The third frame will be used for customizable options.
Thank you greatly! - Eric
#!/usr/bin/perl
($port) = @ARGV;
$port = 2345 unless $port;
$AF_INET = 2;
$SOCK_STREAM = 1;
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname('tcp');
if ($port !~ /^\d+$/) {
($name, $aliases, $port) = getservbyport($port, 'tcp');
}
print "Port = $port\n";
$this = pack($sockaddr, $AF_INET, $port, "\0\0\0\0");
socket(LISTEN, $AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
bind(LISTEN,$this) || die "bind: $!";
listen(LISTEN,5) || die "connect: $!";
select(LISTEN); $| = 1; select(stdout);
print "Listening for connections....\n";
while (1) {
# each time, create the select bit array
$bits = 0;
for (@CLIENTS) {
vec ($bits, fileno ($_), 1) = 1;
}
vec ($bits, fileno (LISTEN), 1) = 1;
#OK, wait until something comes in.
$nfound = select($rbits=$bits,undef,
#OK, something woke us up.
# see if it is a new connection...
if (vec($rbits, fileno(LISTEN), 1)) {
# new connection
accept (NS, LISTEN);
push (@CLIENTS, NS); }
#no, try the clients
$incoming = undef;
for (@CLIENTS) {
if (vec ($rbits, fileno ($_), 1)) {
#OK, this client's got something, read a line...
$incoming .= <$_>; } }
# next, send $incoming to all clients...
if ($incoming) {
for (@CLIENTS) {
print $_ "$incoming\n"; } }
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: ozoPosted on 1997-08-28 at 20:29:52ID: 1204925
Comments are available to members only. Sign up or Log in to view these comments.