
halmstad
New User
Feb 13, 2007, 5:00 AM
Post #1 of 3
(734 views)
|
|
Directory listing
|
Can't Post
|
|
Hi all, I am new to perl i need this one to be solved I have a Perl script which runs in server and a script also runs in client now when client enters a (say dirlist) in client script then the server should return the directory listing of the OS presently i am working in Windows. within the while loop we need to insert a conditional statement which yields the directory listing.. can anyone pls help me ... my server script is #!/usr/bin/perl -w #This is a very simple server for tcp/ip connections. #Only one connection at a time is processed #It uses port 5555 by default use Socket; #the library with sockets functions # Define default values for host and port $server_port = "5555"; $server_name = "localhost"; # Give the user a chance to change the settings print "Enter servername and port or return for default (localhost:5555): "; unless( ($input = <STDIN>) eq "\n" ) { chomp $input; ($server_name, $server_port) = split /:/, $input; # separate the values separated with : } $ipaddress = inet_aton($server_name); $server_address = sockaddr_in($server_port, INADDR_ANY); $protocol = getprotobyname("tcp"); print STDOUT "Perl's server on $ipaddress\n"; print STDOUT "Perl's full address $server_address\n"; print STDOUT "Host: $server_name\tPort: $server_port\n"; socket(SERVER, PF_INET, SOCK_STREAM, $protocol) || die ("SOCKET: $!"); print STDOUT "... created socket on $server_name ...\n"; setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1); # so we can restart our server quickly select(SERVER); # Make SERVER the default handler, i.e. where print prints without explicit handler $| = 1; #Flush buffers bind(SERVER, $server_address) or die "Couldn't bind to port $server_port : $!\n"; print STDOUT "... now bound socket to port $server_port ...\n"; # establish a queue for incoming connections listen(SERVER, SOMAXCONN) or die "Couldn't listen on port $server_port : $!\n"; print STDOUT "... $server_name listens on port $server_port ...\n"; # accept and process connections while (accept(CLIENT, SERVER)) { select (CLIENT); # Make CLIENT the default handler $| = 1; while(1) { #For sendeing and receiving several messages $counter++; # do something with CLIENT $intext = <CLIENT>; # read a line from the client if($intext =~ m/^(q|Q|(quit)|(Quit)|(QUIT)|\\n)/) { # match for different quit "commands" from client print STDOUT "client quits\n"; last; # jump out of the inner while loop that is always true } print STDOUT "=>", $intext; # print to server standard output print CLIENT "Been on Server $counter\n"; # Send a line of text to the client } } close(SERVER);
|