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

I come seeking wisdom.
I wrote perl client and server socket programs to transfer files. They work fine when passing between themselves. Now I need to send and receive files from pro*c socket programs. I attempted to do this today, and the sockets make connections, but the files sent and received are 0 bytes.
I looked into a few reasons this might be, and saw that the pro*c programs send and receive STX and ETX at the start and end of files. I thought this was part of the IO::socket and I didn't have to code this in, am I wrong? What else am I missing here?
Does anyone have experience with this? I know samples of code would help, but they're too long to paste here.

Thanks
  • Comment on File Transfer between c and perl sockets

Replies are listed 'Best First'.
Re: File Transfer between c and perl sockets
by Merlin42 (Friar) on Nov 03, 2001 at 01:18 UTC
    I am guessing that sending STX and ETX is part of the protocol for this pro*c thing. This is definately not part of IO::socket. A socket is to be considered a stream of bytes (assuming TCP) and nothing more. My guess is that the STX/ETX are there to allow several files to be sent over a single socket connection. In http/1.0 eg each file is sent in a seperate connection so closing the connection signals EOF. One thing you might have to worry about is any kind of escaping/stuffing required in case the file happens to contain ETX.
      I was able to get this working, so I wanted to explain what I was talking about earlier. Yes, IO::socket works simply by opening and closing connections, and so do the c programs I need the PERL to communicate with. But the difference is the c programs need a flag to tell it when the transactions started and ended, STX and ETX whose unix octals are \002 and \003. I was able to get this working simply by adding two print $server lines with the \002 and \003 before and after the files sent.

      By the way pro*c is just a version of c that works with embedded sql. It really has nothing to do with the sockets other than that the author was using a table to store constants in.
Re: File Transfer between c and perl sockets
by talexb (Chancellor) on Dec 20, 2001 at 21:21 UTC
    In the past, STX and ETX have been used to indicate the Start and End of TeXt. There was also an associated Start Of Header or SOH. So a normal message might have been

    SOH Header goes here STX Text goes here ETX

    In my experience with Poll Select transactions on a 3201 line, ETX was also used as an end-of-file marker that was followed by an 8-bit checksum.

    "Excellent. Release the hounds." -- Monty Burns.

      I'm puzzled as to why this node has been --'d. As far as I know, the information is accurate. If someone can suggest why it is unpopular, I'd appreciate it.

      --t. alex

      "Here's the chocolates, and here's the flowers. Now how 'bout it, widder hen, will ya marry me?" --Foghorn Leghorn