Exemple #1
0
//! \brief
void IncomingUdp::onExecute()
{
    char buffer[ max_packet_size ];     // TODO: Member variable? Allow max_packet_size to be defined by configuration

    // Memory allocation comes from round-robin memory buffer(s) to remove
    // the necessity for new/delete blocks

    while ( isActive() )
    {
        const int dataLength = m_socket.recv( buffer, max_packet_size );
        if ( dataLength < 0 )
        {
            if ( isActive() )
            {
                processSocketError( dataLength );
            }
        }
        else if ( dataLength > 0 )  // TODO: Simpler if the message queue handles this?
        {
            m_queue->push( buffer, dataLength );
            
            // TODO: Should validate packet then pass it into message queue, we shouldn't know about UserInfo at this level.
            // TODO: Decrypt packet content
            UserInfo *user = findUser( packetInfo.publicKey );
            if ( user && user->ipAddress == packetInfo.ipAddress )
            {
                user->queueMessage( buffer, dataLength );
            }
            else
            {
                m_log->Error( kModuleName, "Received unexpected UDP packet.\n" );
            }
        }
    }
}
Exemple #2
0
Client::Client()
{
    _config = Config::instance();
    _socket = new QTcpSocket;
    connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(processSocketError(QAbstractSocket::SocketError)));
    connect(_socket, SIGNAL(readyRead()), this, SLOT(readData()));
    connect(this, SIGNAL(newMessage(const Message*)), this, SLOT(processNewMessage(const Message*)));
}
Exemple #3
0
INDI::BaseClientQt::BaseClientQt()
{
    cServer = "localhost";
    cPort   = 7624;
    sConnected = false;
    verbose = false;
    lillp=NULL;

    timeout_sec=3;
    timeout_us=0;

    connect(&client_socket, SIGNAL(readyRead()), this, SLOT(listenINDI()));
    connect(&client_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(processSocketError(QAbstractSocket::SocketError)));
}
void KSocketTransactionHandler::handleNewSocketConnection()
{
    // create a new socket in the thread context:
    tcpSocket = new QTcpSocket(this);

    qDebug() << "outgoing Socket Connection to: ";
    qDebug() << "IP  :" << serverIPAddress;
    qDebug() << "Port:" << serverPortNumber;

    // connect underlying socket connected signal to our processor.
    QObject::connect(tcpSocket,     SIGNAL(connected()),
                     this,          SLOT(processSocketConnected()));

    // connect the scoket data signal to our processor.
    QObject::connect(tcpSocket,     SIGNAL(readyRead()),
                     this,          SLOT(processReadyReadData()));

    // connect underlying socket error signal to our processor.
    QObject::connect(tcpSocket,     SIGNAL(error(QAbstractSocket::SocketError)),
                     this,          SLOT(processSocketError(QAbstractSocket::SocketError)));

    tcpSocket->connectToHost(serverIPAddress,serverPortNumber);
}
void KSocketTransactionHandler::handleIncomingSocketConnection()
{
    // create a new socket in the thread context:
    tcpSocket = new QTcpSocket(this);

    // try to accept the connection:
    if (tcpSocket->setSocketDescriptor(socketDescriptor) == false)
    {
        qDebug() << "incoming Socket Connection *NOT ACCEPTED* From:"
                 <<(tcpSocket->peerAddress()).toString()
                 <<":"
                 << tcpSocket->peerPort();

        emit socketError(this,tcpSocket->error());

        return;
    }

    // get the details of the incoming connection:
    qDebug() << "incoming Socket Connection ACCEPTED From:"
             <<(tcpSocket->peerAddress()).toString()
             <<":"
             << tcpSocket->peerPort();

    // connect the scoket data signal to our processor.
    QObject::connect(tcpSocket,     SIGNAL(readyRead()),
                     this,          SLOT(processReadyReadData()));

    // connect underlying socket error signal to our processor.
    QObject::connect(tcpSocket,     SIGNAL(error(QAbstractSocket::SocketError)),
                     this,          SLOT(processSocketError(QAbstractSocket::SocketError)));


    // if we get here, we accepted the socket connection:
    emit socketAcceptedConnection(this);
}