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() ); }
void TcpClientApp::write() { // This sample is meant to work with only one session at a time. if ( mSession && mSession->getSocket()->is_open() ) { // Write data is packaged as a ci::Buffer. This allows // you to send any kind of data. Because it's more common to // work with strings, the session object has static convenience // methods for converting between std::string and ci::Buffer. Buffer buffer = TcpSession::stringToBuffer( mRequest ); mSession->write( buffer ); } else { // Before we can write, we need to establish a connection // and create a session. Check out the onConnect method. mText.push_back( "Connecting to: " + mHost + ":" + toString( mPort ) ); mClient->connect( mHost, (uint16_t)mPort ); } }