Server... #!c:\perl\bin\perl.exe use strict; use IO::Select; use IO::Socket; my ($filename,$new, $fh, @ready); print "Listening to sockets on port 8080\n"; my $lsn = IO::Socket::INET->new( Listen => 1, LocalAddr => 'localhost', LocalPort => 8080, ) or die "Can't create server socket: $!"; my $sel = new IO::Select( $lsn ); #can_read -> Return an array of handles that are ready for reading. while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket $new = $lsn->accept; $sel->add($new); print "Created a new socket $new\n"; } else { # Process socket print "processing socket $lsn\n"; $filename=<$fh>; print "trying to open file $filename"; open FILE, ">$filename" or die "Can't open: $!"; while (<$fh>) { print FILE $_; } close FILE; # Maybe we have finished with the socket $sel->remove($fh); $fh->close; } } } Client: #!c:\perl\bin\perl.exe use strict; use IO::Socket; use Cwd; my $pwdr=cwd; my $appchoice; my ($res, $sockpass); sub client_connect ($$) { my $peer_addr=shift; my $server = IO::Socket::INET->new(Proto => "tcp", PeerPort => 8080, PeerAddr => "$peer_addr", Timeout => 2000) || die "failed to connect to the server\n"; open FILE, "<full path of filename>" or die"Error: $!\n"; print $server "ivr\n"; while (<FILE>) { print $_; print $server $_; } close FILE; } my $message="hello"; client_connect("localhost","$message");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Client(s) sending file(s) to server using Sockets
by zentara (Cardinal) on Jan 23, 2004 at 15:42 UTC | |
|
Re: Client(s) sending file(s) to server using Sockets
by b10m (Vicar) on Jan 23, 2004 at 12:36 UTC | |
|
Re: Client(s) sending file(s) to server using Sockets
by bageler (Hermit) on Feb 27, 2004 at 05:33 UTC |