05-15-05 10:49 PM
>I am fairly new to programming and so would like to have the gurus to
>help me in one of my programs. I need to create a program that will
>read the data from a file in realtime and transfer the data to my
>headoffice server. Here are the real steps :
>
>1. Read the data from the file that is created by a POS terminal in
>real time. The program I write should know that there is a new data
>appended to the transaction file.
>2. Tranfer the new data in realtime to my headoffice server
>3. On my headoffice server I need another program that will recognize
>that a new data is coming and now it should read that data from the
>send pc and write the data into the database.
The approach I would take would be:
Open a connection to the database;
Open the transaction file;
If appropriate, seek in the transaction file to the end or
to after the last transaction that got stored.
while (1) {
Try to read a record from the transaction file;
If you got EOF, sleep a while waiting for a transaction;
If you got a record, use the connection to the database
to enter the record;
}
I'm assuming the program you need in #3 *IS* the database, and the
API it uses is the way to do a realtime transfer in #2. Many
databases, e.g. MySQL, Oracle, and Postgresql, accept network
connections and have clients you can link with C programs.
The time you sleep should be enough to avoid a lot of "busy waiting"
but not so long it slows down getting transactions to the database,
and depends somewhat on the transaction rate. A few seconds might
be appropriate.
You need to figure out how to start this thing. If when you start
it, all transactions in the transaction file are fresh, start at
the beginning. If you keep track of how far you got, start where
you left off. If all transactions are presumed stale, seek to the
end of the file first (although that would seem to risk missing a
transaction or two). Or, if there's a cheap but foolproof way to
detect a duplicate transaction, use that.
Gordon L. Burditt
[ Post a follow-up to this message ]
|