I am starting a new project and at the same time have just discovered Poco Library, which I find absolutely amazing. However I am a bit lost, as examples are not plenty.
I have a ServerApplication->TCPServer->ServerSocket + TCPServerConnectionFactory->TCPServerconnection approach as indicated by the examples. I am inheriting from the PocoNet classes as instructed. Right now I can run my server as a service, & receive incoming connections.
I want to take an event handling approach to the following: on a per-connection (or per client) basis, handle events such as data available to read on the client socket, error occurred on the client socket (disconnected or timeout), send data without error on client socket.
How do I go about doing it?
Is Poco/Foundation/Events what I am looking for, or is there some mechanism implemented in Poco::Net?
I have seen the Poco::Net::NetExpections but they do not appear to be thrown in my TCPServerConnection-derived class when a netcat connection closes.
What I ended up using is a different approach as TCPServer is a different beast altogether. Following the example posted here I ended up with a class inheriting from ServerApplication, and a class which becomes essentially the connection handler by a SocketReactor.
Deamonizer header:
Deamonizer implementation:
The handler class can be anything as long as it has a conforming Constructor (see Poco::Net documentation for this).
In my case the header looks like this:
How you implement the handler is up to you, provided the only thing that you need to do is register the class methods which handle events like so:
All in all, two classes, a few lines of code, simple and clean. Absolutely starting to love Poco library! 🙂