예제 #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 );
	}
}
예제 #3
0
파일: OPCClient.cpp 프로젝트: UIKit0/forest
void OPCClient::onConnect( TcpSessionRef session ){
    ci::app::console()<< "OPCClient::onConnect "<< endl;

    boost::asio::ip::tcp::no_delay noDelayOption(true);
    session->getSocket()->set_option(noDelayOption);

    // Get the session from the argument and set callbacks.
    // Note that you can use lambdas.
    mSession = session;
    mSession->connectCloseEventHandler( [ & ]()
                                       {
                                           ci::app::console()<< "Disconnected"<< endl;
                                       } );
    mSession->connectErrorEventHandler( &OPCClient::onError, this );
    mSession->connectReadCompleteEventHandler( [ & ]()
                                              {
                                                  ci::app::console()<< "Read complete"<< endl;
                                              } );
    mConnecting = false;
}
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 );
}