Hi folks,

I have a Client (A Till) and a server which I am developing in C#.

I wish to implement some sort of network queuing system. So basically, when a method wants to send some data to the server, it will try first and if it fails, then add it to a "queue" and try to send x seconds again later.

Generally, the data which is being sent to the server is 2 strings, on after the other. The first being an id of some sort, the next being a string which is formatted in XML.

It would be nice if this queue could survive a termination of the application.

Any ideas on how to implement such a thing? Maybe I'm going about this a completly wrong way?

I have this idea of saving the xml files to the hard drive in a queue folder and having a thread constantly running in the background to check for files in this folder and try to send them to the server. Maye there is a better way for this?

Thanks for the help :)

Jonny

You're better off approaching this by writing out an XML file to disk in a directory, then processing the directory and deleting the files if the network send fails. This way you will always have the same command life cycle of generate command -> write to disk -> read from disk -> send -> delete if successful.

Otherwise you will have more code paths and in the long run your solution will probably be hard to maintain. Why don't you have some sort of database running on the till to write the 'commands' to and process it from there? I do extensive POS integration and most registers have a local database that synchs to a primary database so the register can run offline.

the till actually doe have a local database store however I guess I'm not using it effectivly.

Could you maybe elabroate further on this please? That would be great :)

I started writing a method which looks like this:

public void start()
        {
            while (true)
            {
                string[] files = Directory.GetFiles(@".\TRN\", "*.xml");

                foreach (string filename in files)
                {
                    string s = System.IO.File.ReadAllText(filename);

                    try
                    {
                        lock (Network.writer)
                        {
                            Network.writer.Write(s);
                            //Add some code here to delete the current file if sending sucessful
                        }
                        
                    }
                    catch
                    {
                    }

                }
            }
        }

Thanks

How about elaborating on what you are trying to accomplish and we can go from there? The approach all depends on the task at hand...

ok sure,

My aim is to get the till to send an XML file (which I call a TRN) of the transaction just processed to the server. This allows "real-time" stats as well as refunds from other tills (If, for example the refund system was complex and needed a receipt scanned or something).

Now, at the "End of Day", the till will still do a proper sync and verify (Whether that be by syncing databases or re-sending all the xml files again in a zipped file I havn't decided yet).

The sending of the TRN after each transaction is just an added feature really.

Let me know if oyu need further details. I really appreciate your help.

Jonny
P.S. I took your suggestion above about processing the directory at the end of each transaction and seems to do the trick

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.