一.概述
TCPServerConnection继承Poco::Runnable类,是所有被TCPServer创建的TCP server connections的抽象基类,其派生类必须重写Poco::Runnable的run()方法,且TCPServerConnection的子类必须提供TCPServerConnection的工厂模式TCPServerConnectionFactory,TCPServerConnection的run()方法必须执行完整的处理客户端的连接,当run()方法返回时,由TCPServer创建的连接对象server connection object会被销毁,连接也会自动关闭。
二.构造函数与析构函数
TCPServerConnection(const StreamSocket& socket);
根据给定的streamsocket创建一个TCPServerConnection
可以在TCPServerConnection的子类中设置自己需要的参数,并通过构造函数传递进来,具体如下:
class TCPServerConnectionSubclass:public Poco::Net::TCPServerConnection{
public:
TCPServerConnectionSubclass(const StreamSocket& s
const std::string& arg1,
int arg2,
double arg3);
void run();
private:
std::string _arg1;
int _arg2;
double _arg3;
};
构造函数的实现如下:
TCPServerConnection(const StreamSocket& s, const std::string& arg1, int arg2, double arg3):
TCPServerConnection(s), _arg1(arg1), _arg2(arg2), _arg3(arg3)
{
}
virtual ~TCPServerConnection();
销毁该TCPServerConnnection
三.成员方法
StreamSocket& socket();
获取在构造函数中传递进来的StreamSocket的引用
void start();
该方法会调用继承的Poco::Runnable中的run()方法,也能捕获所有被run()方法抛出的异常
PS:初写文章,文笔生涩之处,各位请见谅,若有疑问或者交流的,可加本人YY号:301558660
转载请注明出处:山水间博客, http://blog.csdn.net/linyanwen99/article/details/8020268本文参考:http://blog.csdn.net/poechant/article/details/7484781