in reply to FIle transfer using sockets

First of all PeerPort on client side doesn't match LocalPort on server side, so client can't connect to server.

In order to read file name you should use $file1=<$conn>.

You're reading the whole file into memory before send it to client. That's not a good idea. You'd better use the loop like this:

while (sysread FILE, my $buffer, 4096) { $conn->send($buffer); }
This would help if you plan to send file which doesn't fit into memory.

Replies are listed 'Best First'.
Re^2: FIle transfer using sockets
by ikegami (Patriarch) on May 10, 2009 at 04:25 UTC

    In order to read file name you should use $file1=<$conn>.

    Only if
    print $sock "$file";
    is changed to
    print $sock "$file\n";

      You're right. I suggest something like this for client side:

      print $sock "$file\0";
      and something like this for server:
      { local $/ = "\0"; $file1 = <$conn>; chomp $file1; }

      "\n" isn't portable. And at least on *nix file name may contain "\n"

        You might find Internet Line Terminators interesting. Not that what you recommend wouldn't work, but there might be some value in being consistent with many of the existing protocols.