ConnectionHandler Class

[ LiB ]

I've created a special generic class for the Socket Library called ConnectionHandler (found in SocketLib/ConnectionHandler.h). It defines all the standard handler functions.

 template<typename protocol, typename command> class ConnectionHandler { public:     typedef Connection<protocol> conn;     ConnectionHandler( conn& p_conn ) : m_connection( &p_conn ) {}     virtual void Handle( command p_data ) = 0;     virtual void Enter() = 0;     virtual void Leave() = 0;     virtual void Hungup() = 0;     virtual void Flooded() = 0; protected:     conn* m_connection; }; 

If you look back at Figure 5.3 in Chapter 5, you understand that the ConnectionHandler is essentially an abstract version of the protocol::handler class shown in that figure, which defines only the constructor.

The class has two template parameters: the protocol used with the handler, and the class that defines a command . For example, for a simple Telnet protocol, you would most likely choose something such as std::string to represent a complete Telnet command. Whenever the protocol object for a connection receieves enough data to make a complete command, it packages the data up into a command class and sends it off to the command class's Handle function.

Also note that the class automatically keeps track of a pointer to its connection; it's usually a good idea for each handler to know which connection it is attached to.

If you're not quite sure what the point of this class is, just continue reading; all will become clear in the next section.

[ LiB ]


MUD Game Programming
MUD Game Programming (Premier Press Game Development)
ISBN: 1592000908
EAN: 2147483647
Year: 2003
Pages: 147
Authors: Ron Penton

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net