当前位置: 首页>>代码示例>>C++>>正文


C++ SocketServer::SetSocketEventHandler方法代码示例

本文整理汇总了C++中SocketServer::SetSocketEventHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketServer::SetSocketEventHandler方法的具体用法?C++ SocketServer::SetSocketEventHandler怎么用?C++ SocketServer::SetSocketEventHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketServer的用法示例。


在下文中一共展示了SocketServer::SetSocketEventHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	using namespace Framework;
	using namespace log4cplus;
	using namespace std;
	using namespace TcpSocketServerSide;
	using namespace Business;
	using namespace Business::Handlers;
	
	
	// configure log4cplus
	SharedAppenderPtr appender(new DailyRollingFileAppender(_T("Whisper.log")));
	//tstring patternExp = _T("%-5p - %Y-%m-%d %H:%M:%S - %l - %m%n");
	tstring patternExp = _T("%-5p - %D - %l - %m%n");
	auto_ptr<Layout> layout(new PatternLayout(patternExp));
	appender->setLayout(layout);
	Logger logger = Logger::getRoot();
	logger.addAppender(appender);

	// configure Framework
	Configurations::BufferSize = 1024;
	Configurations::Logger = &logger;

	try{

		ITaskFactory* taskFactory = new DefaultTaskFactory(1);

		SocketServer* server = new TcpSocketServer(
			"127.0.0.1", //"192.168.1.103",//
			8888,
			taskFactory
			);

		auto dispatcher = new TcpSocketEventDispatcher(*server);
		auto socketFactory = new TcpSocketFactory();
		auto manager = new TcpConnectionManager(*server, *dispatcher, *socketFactory);
		auto handler = new WhisperSocketEventHandler(*server);
		auto serverEventHandler = 
			new WhisperSocketEventHandler::ServerEventHandler(
			*server,
			*handler
			);

		/* register message handler */
		PacketDispatcher& packetDispatcher = handler->GetPacketDispatcher();
		packetDispatcher.Register(new AuthenticateRequestHandler());


		/* register message handler */

		server->SetSocketEventDispatcher(dispatcher);
		server->SetConnectionManager(manager);
		server->SetSocketEventHandler(handler);
		server->SetServerEventHandler(serverEventHandler);

		server->Start();

		/*Sleep(10*1000);*/
		//server->Shutdown();

		server->WaitForShutdown();
		delete server;
		cout << " Server closed." << endl;
	}
	catch(std::exception &ex){
		cout << ex.what() << endl;
	}

	cin.get();

	return 0;
}
开发者ID:xinsuiyuer,项目名称:IOCompletionPort,代码行数:72,代码来源:WhisperServer.cpp


注:本文中的SocketServer::SetSocketEventHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。