void TCPReceiveBytes::onNewConnection(core::SharedPointer<core::io::tcp::TCPConnection> connection) {
    if (connection.isValid()) {
        cout << "Handle a new connection." << endl;

        // Set this class as StringListener to receive
        // data from this connection.
        connection->setStringListener(this);

        // Set this class also as ConnectionListener to
        // handle errors originating from this connection.
        connection->setConnectionListener(this);

        // Start receiving data from this connection.
        connection->start();

        // We keep this connection open only for one
        // second before we close it.
        const uint32_t ONE_SECOND = 1000 * 1000;
        core::base::Thread::usleepFor(ONE_SECOND);

        // Stop this connection.
        connection->stop();

        // Unregister the listeners.
        connection->setStringListener(NULL);
        connection->setConnectionListener(NULL);
    }
}
Beispiel #2
0
    void SuperComponent::onNewModule(core::SharedPointer<core::dmcp::connection::ModuleConnection> mc) {
        if (mc.isValid()) {
            mc->waitForModuleDescription();
            CLOG1 << "[odsupercomponent]: New connected module " << mc->getModuleDescriptor().toString() << endl;

            ConnectedModule* module = new ConnectedModule(mc, coredata::dmcp::ModuleStateMessage::NOT_RUNNING);
            mc->setModuleStateListener(this);

            if (m_modules.hasModule(mc->getModuleDescriptor())) {
                clog << "[odsupercomponent]: WARNING!!! MODULE " << mc->getModuleDescriptor().toString() << " AREADY CONNECTED: Consider using --id to differentiate modules!" << endl;
            }
            else {
                m_modules.addModule(mc->getModuleDescriptor(), module);
            }
        }
    }