Front page | perl.beginners |
Postings from February 2002
RE: socket help, last time i promise ;)
Thread Previous
|
Thread Next
From:
Scott L Ryan
Date:
February 6, 2002 08:26
Subject:
RE: socket help, last time i promise ;)
Message ID:
004501c1af2b$23d34f30$8824e90a@en38060
Thanks for the response... but It is now fixed ;) I have highlighted
what was the issue - walter you are the don!
#!/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;
print "msg>\n\r";
$input = <CLIENT>;
chomp $input;
chop $input;
&breakshit;
open (OUTSTUFF, "checked");
@responses = <OUTSTUFF>;
close OUTSTUFF;
print @responses;
system("cp /dev/null checked");
}
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 ($ldapargs{conpass} ne "admin123") {
print "Error:Tac:Invalid Password, cannot complete request\n";}
else {
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{aparty} $ldapargs{accountnum}
$ldapargs{consult}");
} elsif ($script eq "dialin_changegroup") {
system("/usr/local/bin/onenet/OTN/dialin_changegroup.pl $ldapargs{uid}
$ldapargs{group}
ldapargs{consult}");
} elsif ($script eq "dialin_changepassword") {
system("/usr/local/bin/onenet/OTN/dialin_changepassword.pl
$ldapargs{uid} $ldapargs{pass
word} $ldapargs{consult}");
}
}
}
Regards,
Scott L Ryan
OneTel.Net ISP Engineer
-----Original Message-----
From: Bob Showalter [mailto:Bob_Showalter@taylorwhite.com]
Sent: 06 February 2002 16:08
To: 'Scott L Ryan'; beginners@perl.org
Subject: RE: socket help, last time i promise ;)
> -----Original Message-----
> From: Scott L Ryan [mailto:scotty@onetel.net.uk]
> Sent: Wednesday, February 06, 2002 7:29 AM
> To: beginners@perl.org
> Subject: socket help, last time i promise ;)
>
>
> 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";
I recommend you use IO::Socket instead of this. Much cleaner
interface.
> while (accept(CLIENT, SERVER)) {
OK, here's where we get an incoming connection. Why aren't you
displaying your message right here? Or maybe I don't understand
what you mean by "display a message". Do you mean on the server
or on the client?
> *STDOUT = *CLIENT;
> print "msg>";
This prompt goes to the client. You need to set autoflush on,
because the prompt will not get to the client. If you use
IO::Socket, it will take care of that for you.
> $input = <CLIENT>;
Here's where we block, waiting for the client to send a line.
I can't see where you are "displaying a message".
Thread Previous
|
Thread Next