Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
thanks,use IO::Select; use IO::Socket; my $client_port; my $rtk_connection; my $listening_port; my $rtk_port; my $rtk_ip; my $accepted_client; $listening_port=8019; $rtk_port=4004; $rtk_ip='000.000.000.000'; $client_port=IO::Socket::INET->new('LocalPort'=>$listening_port, 'Reus +e'=>1, 'Listen'=>512, 'Proto'=>'tcp') || warn "Can not create to list +ening socket on port $listening_port: $!\n"; $rtk_connection= IO::Socket::INET->new('PeerAddr'=>$rtk_ip, 'PeerPort' + =>$rtk_port, 'Reuse'=>1, 'Proto'=>'tcp') || warn "Can not create rtk + socket on IP $rtk_ip and port $rtk_port: $!\n"; $SIG{'CHLD'}='IGNORE'; while(1){ $accepted_client=$client_port->accept() ; if($accepted_client){ print "Client accepted\n"; } if(!$accepted_client){ print "Client could not be accepted: $!\n"; next; } $spawn=fork(); if(!defined($spawn)){ print "Could not spawn child process: $!\n"; } elsif($spawn == 0){ $client_port->close(); print "Spawned child A\n"; &rtk($accepted_client, $rtk_connection); } else{ print "Spawned child B\n"; $accepted_client->close(); } } sub rtk{ ($ac,$rs)=@_; $ac->autoflush(0); $rs->autoflush(0); while($ac){ $drl=sysread($rs, $rd, 1024); if(!$drl){ print "No stream: $!\n"; exit(0); } $dwl=syswrite($ac, $rd, 1024); if(!$dwl){ print "Client Disconnected: $!\n"; exit(0); } } }
20040603 Edit by jeffa: Changed title from 'Sockets'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Single user to multi user socket server
by Thelonius (Priest) on Jun 01, 2004 at 23:15 UTC | |
by Anonymous Monk on Jun 02, 2004 at 00:26 UTC | |
|
Re: Single user to multi user socket server
by tachyon (Chancellor) on Jun 02, 2004 at 02:00 UTC | |
by thospel (Hermit) on Jun 02, 2004 at 03:33 UTC | |
by tachyon (Chancellor) on Jun 02, 2004 at 06:42 UTC | |
by thospel (Hermit) on Jun 02, 2004 at 14:08 UTC | |
by Anonymous Monk on Jun 02, 2004 at 17:27 UTC | |
by tachyon (Chancellor) on Jun 03, 2004 at 02:14 UTC | |
|