in reply to File/Data Streaming over a socket

I usually use Net::EasyTCP for this, but this is the simplest code you could probably find. If you are wanting to use this for multiple clients, you will have to go to a "forking design", unless you files are very small. With code as simple as this, you are bound to run into problems, for which you will see the benefit of using Net::Easy::TCP. For instance, is this open to the net?, you should have a port-password at the very least.
####Server########### #!/usr/bin/perl use IO::Socket; my $server = IO::Socket::INET->new( Listen => 5, LocalAddr => 'localhost', LocalPort => 5050, Proto => 'tcp' ) or die "Can't create server socket: $!"; my $client = $server->accept; open FILE, ">out" or die "Can't open: $!"; while (<$client>) { print FILE $_; } close FILE; __END__ #and the Client ########## #!/usr/bin/perl use IO::Socket; my $server = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => 5050, Proto => 'tcp' ) or die "Can't create client socket: $!"; open FILE, "in"; while (<FILE>) { print $server $_; } close FILE

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: File/Data Streaming over a socket
by petesull (Initiate) on Mar 17, 2005 at 21:55 UTC
    Please forgive my ignorance, but how do you implement a socket password? This will be open to the internet and files that it will receive will at most, 200Kb. Thanks all for your help to!
      It's alot easier to use Net::EasyTCP. Here are a couple of snippets that I posted awhile back Sockets-File-Upload with Net::EasyTCP. It has port passwords, usernames and logons, and is encrypted. Read the Net::EasyTCP docs for details. Now Net::EasyTCP uses IO::Select, so that means if a second client connects, while another is currently uploading, it will have to wait for the first upload to finish.(Remember the forking? This dosn't fork). Net::EasyTCP also has a "refuse connection" list, you can employ if out on the NET and some ipaddress is hacking, but not logging on. You can do something like count logon attempts, then after 10 failures, put them in a @banned-ips list.

      Also, when I wrote that snippet, there was a problem with RSA(as mentioned), but the module now has an option to handle this:

      my @nocrypt = qw(Crypt::RSA); #too slow, but more secure #my @nocompress = qw(Compress::LZF); #just testing this feature $server = new Net::EasyTCP( host => $host, mode => 'server', port => $port, password => $portpassword, # if asymmetric encryption # use a port password donotencryptwith => \@nocrypt, # donotencrypt => 1,
      I have another snippet that implements these ideas at ztk-enchat encrypted server client

      I'm not really a human, but I play one on earth. flash japh

      1) A socket is just an association between a protocol ( port, address ) and a descriptor ( filehandle ).

      2) An application connected to the public internet with only password protection offers only false security.

      3) Go to http://search.cpan.org and search for security.

      4) Posting a new question in an existing thread is a faux pax.

      s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}