I’m testing out a proof-of-concept that sends two files over a TCP connection to a remote server, all using Perl. I’m running into a problem, however, with sending multiple files over. Currently, I have the client (hosted on Windows, running ActiveState Perl) that wants to send over 2 CSV files to the remote server (running some form of RedHat). As the process goes, the client will print out, line-by-line, the contents of the CSV file, and when that’s done, it’ll send over a message to the server. The server should then intercept that message, and switch the file to write to to another CSV file.
However, the server is just one large file, where I want it to split what it receives into two files. So, my real question is this: what is the easiest way, using Perl, to send over two files on a TCP connection? I’d PREFER to use builtin modules, such as IO::Sockets, but if I have to download an external module to make the process simple, I can do that too.
Thank you for any and all answers!
[EDIT]: It seems it was line endings that were affecting me, along with the fact that the last line of a file doesn’t have a “\n” appended to it. Replacing Windows line endings with Unix ones seemed to do the trick, along with some other formatting with the “End Of File” message. Thanks to all those who answered!
Send a header with the length of the first file. Since they’re text files, and this is Perl, it might be better to use the number of lines in the file. On the other side, read that number of lines in as the first file, then all of the rest as the second. This principle can be extended for any number of files.
Edit: You’ll also want to translate the windows line endings to linux ones. A simple s/\r\n/\n/; should do the trick.