Пример #1
0
void WebClientApp::write()
{
	// This sample is meant to work with only one session at a time
	if ( mSession && mSession->getSocket()->is_open() ) {
		return;
	}
		
	mText.push_back( "Connecting to:\n" + mHost + ":" + toString( mPort ) );
	
	mClient->connect( mHost, (uint16_t)mPort );		
}
Пример #2
0
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 );
	}
}
void HttpClientApp::write()
{
	if ( mSession && mSession->getSocket()->is_open() ) {
		return;
	}
	
	// Reset download stats
	mBytesRead		= 0;
	mContentLength	= 0;
	
	// Update request body
	string index	= toString( mIndex );
	mFilename		= index;
	mHttpRequest.setBody( HttpRequest::stringToBuffer( index ) );
	
	mText.push_back( "Connecting to:\n" + mHost + ":2000" );
	
	// Ports <1024 are restricted to root
	mClient->connect( mHost, 2000 );
}