Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Simple perl socket code. Any way to improve/simplify it?

by prodevel (Scribe)
on Jan 23, 2020 at 03:47 UTC ( [id://11111736]=perlquestion: print w/replies, xml ) Need Help??

prodevel has asked for the wisdom of the Perl Monks concerning the following question:

It's been WAAAY too long since I've visited.

Server:
#!/usr/local/bin/perl use IO::Socket::INET qw(CRLF); my $client = IO::Socket::INET->new('blade:12333') or die "new: $@"; while (<$client>) {if ($_ =~ /file: (.*)/) {open(FOUT,">>$1") || die "cannot create: $1";} elsif ($_ =~ /EOF/) {close(FOUT);} else {print FOUT;} }
Client:
#!/usr/local/bin/perl use IO::Socket::INET qw(CRLF); my $client = IO::Socket::INET->new('blade:12333') or die "new: $@"; while (<$client>) {if ($_ =~ /file: (.*)/) {open(FOUT,">$1") || die "cannot create: $1";} elsif ($_ =~ /EOF/) {close(FOUT);} else {print FOUT;} }
Besides the obvious perl security/etc. flags, what do think? I wrote this back in 2004 so I'm curious how it holds up, etc.

Replies are listed 'Best First'.
Re: Simple perl socket code. Any way to improve/simplify it?
by NetWallah (Canon) on Jan 23, 2020 at 18:14 UTC
    Why not preserve sanity, and use scp.

    Yes - it even works on Windows if you install cygwin.

                    "From there to here, from here to there, funny things are everywhere." -- Dr. Seuss

      use scp. Yes - it even works on Windows if you install cygwin.

      No need for cygwin. PuTTY comes with pscp.exe (and psftp.exe) for command line use. If you insist on using a mouse, there is WinSCP that is compatible with PuTTY's way of storing sessions and keys, and it can do scp and sftp as well as classic FTP. All of those programs can use PAgent.exe as SSH authentication agent, so you can work without passwords and type the key's passphrase only once during boot.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Simple perl socket code. Any way to improve/simplify it?
by tybalt89 (Monsignor) on Jan 23, 2020 at 13:59 UTC

    That is not a server.

Re: Simple perl socket code. Any way to improve/simplify it?
by tybalt89 (Monsignor) on Jan 23, 2020 at 05:53 UTC

    That's not a server.

Re: Simple perl socket code. Any way to improve/simplify it?
by Anonymous Monk on Jan 23, 2020 at 06:24 UTC
    what protocol? how many clients at once?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11111736]
Approved by footpad
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found