QStateMachine based server vs threads based server?

  • Hi,

    reading about the threading and other articles and blogs regarding networking I stumbled across the practical examples of the state machine design and eventually Qt StateMachine Framework. It seemed very interesting and I could not resist and gave it a shot - attempting to rewrite my server app using QStateMachine and related classes. This was not just an exercise as I was hoping to eliminate 2 threads I have been permanently using (one for service object that exchange data between clients and one for exiting the app from console) and possibly all threading (I am loosely basing my server on Fortune Threaded Server example).

    Anyway, while it looked really promising at first - the idea of designing my own states and managing my app the way I envisioned and needed - I soon ran into the problem that I had to manage virtually everything. What was previously connecting few objects with signals & slots to manage initialization of the server and making couple function calls in correct order became very convoluted when these things were done State Machine style with dozens lines of code for few simple steps in server initialization. Since I ran into this in the initialization of the server which is arguably very simple compared to the managing incoming clients, their requests, responses, exchanging data, AND because I had to expose somehow all relevant objects to the QStateMachine which for convenience forced me to have them as permanent members rather than temporary when needed... I simply abandoned the idea as it seemed not worth it.

    Maybe I am doing something wrong but I really cannot understand the benefits of State Machine that would be worth this amount of work. At least not in Qt. I understand that with State Machine design one does literally design the same application flow as is seen on the paper chart which is incredibly cool and awesome idea. But I find it excessively hard in practice! As I understood it the primary use is for GUI applications that tends to be very convoluted as well (when custom painting operations are used at least) but I read it should serve any purpose.

    It very well might also be a problem of me being spoiled by Qt that makes coding very very easy and since coding State Machine means designing it from scratch (vs reimplementing a function or two in a convenient subclass) it seems hard.

    Anyway, I would really appreciate any pointers, links or ideas regarding State Machines. I find the idea still very intriguing and I would love to try a server app based on State Machine design. Thanks!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.