Dear List

I have a question regarding this client - server script. I am using two
modules in my script . One is IO::Socket and another is IO::Select. Now my
question is if I want to implement an architecture so that client script
will send a command to the server* [*which doesn't require root privilege to
run ( like ls -l .... ps etc.)* ] *the server script then  execute that
command in the server machine and the output will be displayed again at
client's machine console or output will be stored in the client machine's
specified directory. If yes then how? Is it possible to implement such
architecture by using these two modules? If u people know some good
tutorials related with this type of architecture then please let me know. If
I get any example code available related with this architecture from ur side
I will be highly privileged.

Thanks & Regards In Advance

Anirban Adhikary.







On Tue, Mar 18, 2008 at 6:57 PM, zentara <[EMAIL PROTECTED]> wrote:

> On Tue, 18 Mar 2008 00:32:13 +0530, [EMAIL PROTECTED] ("Anirban
> Adhikary") wrote:
>
> >Dear List
> >I want to write a script using TCP protocol where will be a single server
> >which can handle  multiple client request  simultaneously. I am able to
> >write a script using IO::Socket but In these scripts my server can handle
> >single client suppose my server is printing the IP address of the client
> >and print 10 times hello world like this............ But that is not the
> >thing which I want ............. I need  a script which will print the IP
> >address of the client from which it receives the request and also execute
> >the request which it is receiving from the clients. Regarding this if I
> get
> >u people's help I will be highly obliged.
> >
> >Thanks&Regards in advance
> >Anirban Adhikary.
>
> There are alot of examples on groups.google.com. Search for
> "perl multi-echo chat". But these will get you started.
> Also http://perlmonks.org?node_id=627553 for some more code.
>
>
> #server
> #!/usr/bin/perl
> use IO::Socket;
> use IO::Select;
>
> my @sockets;
> my $machine_addr = 'localhost';
> $main_sock = new IO::Socket::INET(LocalAddr=>$machine_addr,
>      LocalPort=>12345,
>      Proto=>'tcp',
>      Listen=>3,
>            Reuse=>1,
>            );
>
> die "Could not connect: $!" unless $main_sock;
> print "Starting Server\n";
>
> $readable_handles = new IO::Select();
> $readable_handles->add($main_sock);
>
> while (1)
> {
>  ($new_readable) = IO::Select->select($readable_handles, undef, undef,
> 0);
>
>  foreach $sock (@$new_readable)
>  {
>    if ($sock == $main_sock)
>    {
>      $new_sock = $sock->accept();
>      $readable_handles->add($new_sock);
>    }
>    else
>    {
>      $buf = <$sock>;
>      if ($buf)
>      {
>        print "$buf\n";
>        my @sockets = $readable_handles->can_write();
>        #print $sock "You sent $buf\n";
>        foreach my $sck(@sockets){print $sck "$buf\n";}
>
>      }
>      else
>      {
>        $readable_handles->remove($sock);
>        close($sock);
>      }
>    }
>  }
>
> }
>
>
> print "Terminating Server\n";
> close $main_sock;
> getc();
> __END__
>
> #######################################
>
> #client
> #!/usr/bin/perl -w
> use strict;
> use IO::Socket;
>
> my ( $host, $port, $kidpid, $handle, $line );
>
> ( $host, $port ) = ('192.168.0.9',1200);
>
> my $name = shift || '';
> if($name eq ''){print "What's your name?\n"}
> chomp ($name = <>);
>
>
> # create a tcp connection to the specified host and port
> $handle = IO::Socket::INET->new(
>    Proto    => "tcp",
>    PeerAddr => $host,
>    PeerPort => $port
>  )
>  or die "can't connect to port $port on $host: $!";
> $handle->autoflush(1);    # so output gets there right away
> print STDERR "[Connected to $host:$port]\n";
>
> # split the program into two processes, identical twins
> die "can't fork: $!" unless defined( $kidpid = fork() );
>
> # the if{} block runs only in the parent process
> if ($kidpid) {
>
>    # copy the socket to standard output
>    while ( defined( $line = <$handle> ) ) {
>                      print STDOUT $line;
>                      }
>    kill( "TERM", $kidpid );    # send SIGTERM to child
> }
>
> # the else{} block runs only in the child process
> else {
>
>    # copy standard input to the socket
>    while ( defined( $line = <STDIN> ) ) {
>        print $handle "$name->$line";
>    }
> }
> __END__
>
>
> Remember, IO::Select shares time amoung the sockets. So if
> your messages are short, things will work fine. BUT if one client
> tries to transfer a huge file, select will block all other clients until
> the one client-hog is done. In that case you may need a "forking server"
> or a "threaded server".
>
>
> zentara
>
>
>
>
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Reply via email to