develooper Front page | perl.beginners | Postings from February 2002

Re: socket help, last time i promise ;)

Thread Previous
From:
walter valenti
Date:
February 6, 2002 06:13
Subject:
Re: socket help, last time i promise ;)
Message ID:
3C613A69.405@yahoo.it
Scott L Ryan wrote:

>I want to display a message when a client connects to the server.
> 
>msg>
> 
>right now, I cannot seem to display that message until I have received
>something from the client and I want to display it before the client
>sends anything. puzzling..
> 
>#!/usr/local/bin/perl
> 
>use Socket;
> 
>if (!@ARGV) {
>print "Script cannot be called with no Port Number.... doh!\n";
>} else {
>$server_port = $ARGV[0];
> 
>socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
> 
>setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1);
> 
>$my_addr = sockaddr_in($server_port, INADDR_ANY);
> 
>bind(SERVER, $my_addr) or die "couldnt bind";
>listen(SERVER, SOMAXCONN) or die "cant listen";
>while (accept(CLIENT, SERVER)) {
>*STDOUT = *CLIENT;
>
$|=1; ### to force fflush() system

>print "msg>";
>$input = <CLIENT>;
>chomp $input;
>chop $input;
>&breakshit;
>open (OUTSTUFF, "checked");
>@responses = <OUTSTUFF>;
>close OUTSTUFF;
>#chomp @responses;
>print @responses
>#print OUTSTUFF $input;
>#close OUTSTUFF;
>}
>close(SERVER);
>}
>sub breakshit() {
>($junk, $info) = split(/:/,$input);
>@input_values = split(/&/,$info);
>foreach $value (@input_values){
>($key, $value) = split(/=/,$value);
>$ldapargs{$key} = $value;
>}
>$script = $ldapargs{type};
>if ($script eq "overall_status") {
>system("/usr/local/bin/onenet/OTN/overall_status.pl $ldapargs{uid}
>$ldapargs{consult}");
>} elsif ($script eq "dialin_create") {
>system("/usr/local/bin/onenet/OTN/dialin_create.pl $ldapargs{uid}
>$ldapargs{password} $l
>dapargs{group} ldapargs{consult}");
>} elsif ($script eq "dialin_changegroup") {
>system("/usr/local/bin/onenet/OTN/dialin_changegroup.pl $ldapargs{uid}
>$ldapargs{group}
>ldapargs{consult}");
>}
>}
> 
> 
>Regards, 
>Scott L Ryan
>OneTel.Net ISP Engineer
> 
> 
>




Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About