Exemplo n.º 1
0
void WebClientApp::onConnect( TcpSessionRef session )
{
	mHttpResponse	= HttpResponse();
	mSession		= session;
	mText.push_back( "Connected" );
	
	mSession->connectCloseEventHandler( &WebClientApp::onClose, this );
	mSession->connectErrorEventHandler( &WebClientApp::onError, this );
	mSession->connectReadCompleteEventHandler( &WebClientApp::onReadComplete, this );
	mSession->connectReadEventHandler( &WebClientApp::onRead, this );
	mSession->connectWriteEventHandler( &WebClientApp::onWrite, this );
	
	mSession->write( mHttpRequest.toBuffer() );
}
Exemplo n.º 2
0
void TcpClientApp::onConnect( TcpSessionRef session )
{
	mText.push_back( "Connected" );

	// Get the session from the argument and set callbacks.
	// Note that you can use lambdas.
	mSession = session;
	mSession->connectCloseEventHandler( [ & ]()
	{
		mText.push_back( "Disconnected" );
	} );
	mSession->connectErrorEventHandler( &TcpClientApp::onError, this );
	mSession->connectReadCompleteEventHandler( [ & ]()
	{
		mText.push_back( "Read complete" );
	} );
	mSession->connectReadEventHandler( &TcpClientApp::onRead, this );
	mSession->connectWriteEventHandler( &TcpClientApp::onWrite, this );

	write();
}