forking on NT4 
Author Message
 forking on NT4

I'm trying to write a program using IO::Socket to accept multiple
connections using fork on an NT 4 server.

The script basically echo's what I type when I telnet to the port.  I can
connect multiple times with telnet but what I'm seeing is that nothing is
echoed back to the second telnet connection till the first one disconnects.
Is this an NT thing or am I missing something in the forking process?

Any pointers?

TIA
Jay



Tue, 21 Sep 2004 23:58:53 GMT  
 forking on NT4

Quote:

> I'm trying to write a program using IO::Socket to accept multiple
> connections using fork on an NT 4 server.

> The script basically echo's what I type when I telnet to the port.  I can
> connect multiple times with telnet but what I'm seeing is that nothing is
> echoed back to the second telnet connection till the first one disconnects.
> Is this an NT thing or am I missing something in the forking process?

> Any pointers?

> TIA
> Jay

Jay,

   Easier not to use fork on NT?   If you are using ActiveState they
have a good listener for multiple connections in their examples.   I
have a slightly modified version I will post here...   My
modifications were just to print the connecting clients name.

Good Luck!

#!/usr/bin/perl -w

use IO::Socket;
use IO::Select;
use Net::hostent;              

# Create a socket to listen on.
#
my $listener = IO::Socket::INET->new( LocalPort => 8005, Listen => 5,
Reuse => 1 );

die "Can't create socket for listening: $!" unless $listener;
print "Listening for connections on port 8005\n";

my $readable = IO::Select->new;     # Create a new IO::Select object
$readable->add($listener);          # Add the listener to it

while(1) {

# Get a list of sockets that are ready to talk to us.
#
    my ($ready) = IO::Select->select($readable, undef, undef, undef);

# Is it a new connection?
#
        if($client == $listener) {

# Accept the connection and add it to our readable list.
#
            my $new_sock = $listener->accept;
            $new_sock->autoflush(1);
            $readable->add($new_sock) if $new_sock;
            $hostinfo = gethostbyaddr($new_sock->peeraddr);
            my $clientname = $hostinfo->name || $new_sock->peerhost;
            ($clientname) = split(/.clt/, $clientname);

            printf "[Connect from %s]\n", $clientname;

            print $new_sock "Welcome $clientname!\r\n";

        } else {  # It's an established connection

            $hostinfo = gethostbyaddr($client->peeraddr);
            my $clientname = $hostinfo->name || $client->peerhost;

            my $buf = <$client>;   # Try to read a line

# Was there anyone on the other end?
#
            if( defined $buf ) {

# If they said goodbye, close the socket. If not,
# echo what they said to us.
#
                if ($buf =~ /goodbye/i) {
                    print $client "See you later!\n";
                    $readable->remove($client);
                    $client->close;
                } else {
                    print $client "You said: $buf\n";
                    print "$clientname said $buf\n";
                }

            } else { # The client disconnected.

                $readable->remove($client);
                $client->close;
                print STDERR "$clientname closed connection\n";

            }
        }
    }

Quote:
}



Tue, 12 Oct 2004 02:08:10 GMT  
 forking on NT4
Scott,

Thanks alot, I'll try it out!

Jay



Quote:
> > I'm trying to write a program using IO::Socket to accept multiple
> > connections using fork on an NT 4 server.

> > The script basically echo's what I type when I telnet to the port.  I
can
> > connect multiple times with telnet but what I'm seeing is that nothing
is
> > echoed back to the second telnet connection till the first one
disconnects.
> > Is this an NT thing or am I missing something in the forking process?

> > Any pointers?

> > TIA
> > Jay

> Jay,

>    Easier not to use fork on NT?   If you are using ActiveState they
> have a good listener for multiple connections in their examples.   I
> have a slightly modified version I will post here...   My
> modifications were just to print the connecting clients name.

> Good Luck!

> #!/usr/bin/perl -w

> use IO::Socket;
> use IO::Select;
> use Net::hostent;

> # Create a socket to listen on.
> #
> my $listener = IO::Socket::INET->new( LocalPort => 8005, Listen => 5,
> Reuse => 1 );

> die "Can't create socket for listening: $!" unless $listener;
> print "Listening for connections on port 8005\n";

> my $readable = IO::Select->new;     # Create a new IO::Select object
> $readable->add($listener);          # Add the listener to it

> while(1) {

> # Get a list of sockets that are ready to talk to us.
> #
>     my ($ready) = IO::Select->select($readable, undef, undef, undef);

> # Is it a new connection?
> #
> if($client == $listener) {

> # Accept the connection and add it to our readable list.
> #
>     my $new_sock = $listener->accept;
>     $new_sock->autoflush(1);
>     $readable->add($new_sock) if $new_sock;
>     $hostinfo = gethostbyaddr($new_sock->peeraddr);
>     my $clientname = $hostinfo->name || $new_sock->peerhost;
>     ($clientname) = split(/.clt/, $clientname);

>     printf "[Connect from %s]\n", $clientname;

>     print $new_sock "Welcome $clientname!\r\n";

> } else {  # It's an established connection

>     $hostinfo = gethostbyaddr($client->peeraddr);
>     my $clientname = $hostinfo->name || $client->peerhost;

>     my $buf = <$client>;   # Try to read a line

> # Was there anyone on the other end?
> #
>     if( defined $buf ) {

> # If they said goodbye, close the socket. If not,
> # echo what they said to us.
> #
> if ($buf =~ /goodbye/i) {
>     print $client "See you later!\n";
>     $readable->remove($client);
>     $client->close;
> } else {
>     print $client "You said: $buf\n";
>     print "$clientname said $buf\n";
> }

>     } else { # The client disconnected.

> $readable->remove($client);
> $client->close;
> print STDERR "$clientname closed connection\n";

>     }
> }
>     }
> }



Tue, 12 Oct 2004 02:35:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Fork Does not Fork

2. fork without fork?

3. Unexpected glob behavior nt4-ActivePerl-5.6

4. Using Perl Modules in an NT4.0 Environment

5. install probs w LWP modules - NT4

6. getting groupmembership in a nt4-domain

7. unlink - Problem NT4

8. Problems with sockets using perl on NT4.0

9. NT4 WIN32::*** modify rights of a directory or share

10. Has somebody already install GD.pm on win NT4

11. GD on NT4

12. About Perl script to upload to ftp server in NT4

 

 
Powered by phpBB® Forum Software