Beispiel #1
0
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    connector = new Server(this);



    myself.setName(QString("user ") + QString::number(qrand()));

    // connect(connector,SIGNAL(massageReceived(QByteArray)),this,SLOT(audioOutput(QByteArray))); \\

    connect(connector,SIGNAL(massageReceived(QByteArray)),this,SLOT(audioOutput(QByteArray))); \

    decoder = new AudioDecoder(this);
    recorder = new AudioRecorder(this);
    connect(recorder,SIGNAL(audioBufferder(QByteArray)), connector, SLOT(sendMessage(QByteArray)));

    ui->message_output->setReadOnly(true);
    ui->text_log->setReadOnly(true);


    QString host_rand = QString::number(rand() * 255) + QString(".") +
            QString::number(rand() * 255) + QString(".") +
            QString::number(rand() * 255) + QString(".") +
            QString::number(rand() * 255);
    // QHostAddress host = QHostAddress(host_rand);
    // QHostAddress host =  QHostAddress::LocalHost ;;
    QHostAddress host =  QHostAddress::Broadcast;
    connector->setPort(qrand());
    connector->setHostAdress(host);
    connector->bindHostPort();

    // connector->joinMulticastGroup(host);

    client_tcp = new ClientTcp(this);
    server_tcp = new ServerTCP(this);
    connect(client_tcp,SIGNAL(sendedMessage(QByteArray)),this,SLOT(messageOutput(QByteArray)));
    connect(client_tcp,SIGNAL(receivedMessage(QByteArray)),this,SLOT(messageOutput(QByteArray)));
    connect(client_tcp,SIGNAL(connected()),this,SLOT(serverFounded()));

    //connect(server_tcp,SIGNAL(),this,SLOT());
    connect(server_tcp,SIGNAL(sendedMessage(QByteArray)),this,SLOT(messageOutput(QByteArray)));
    connect(server_tcp,SIGNAL(receivedMessage(QByteArray)),this,SLOT(messageOutput(QByteArray)));
    connect(server_tcp,SIGNAL(newConnection()),this,SLOT(clientConnected()));

    QHostAddress hosta("127.15.10.12");

    quint16 port = 135665;
    client_tcp->setHostAdress(hosta);
    client_tcp->setPort(port);

    server_tcp->setHostAdress(hosta);
    server_tcp->setPort(port);
    //    connecor->ho



}
Beispiel #2
0
void MainWindow::setupPlayer() {

    TokenMenu *tokenMenu = ui->tokenPage;
    TurnMenu *turnMenu = ui->turnWidget;
    m_Client = new SwitchClient(m_User, tokenMenu, turnMenu);

    connect(m_Client, SIGNAL(sendMessageToChatUi(QString)),
            ui->m_ChatWidget, SLOT(receivedMessage(QString))
    );

    // Initialize ChatWidget with the ChatClient
    ChatClient* chatClient = dynamic_cast<ChatClient*>(
                m_Client->getReceiver(TargetCode::CHAT_CLIENT));
    ui->m_ChatWidget->setSenderClient(chatClient);

    // Initialize MapClient connect
    Receiver *mapClientReceiver = m_Client->getReceiver(TargetCode::MAP_CLIENT);
    MapClient *mapClient = dynamic_cast<MapClient*>(mapClientReceiver);
    connect(mapClient, SIGNAL(openMap(Map*)), this, SLOT(openMap(Map*)));

    // Initialize TokenMenu
    Receiver *tokenMenuClientReceiver = m_Client->getReceiver(TargetCode::TOKEN_MENU_CLIENT);
    TokenMenuClient *tokenMenuClient = dynamic_cast<TokenMenuClient*>(tokenMenuClientReceiver);
    ui->tokenPage->setSenderClient(tokenMenuClient);
    ui->tokenPage->initTokenMenu();

    // Initialize TurnMenu with the TurnMenuClient
    Receiver *turnMenuClientReceiver = m_Client->getReceiver(TargetCode::TURN_MENU_CLIENT);
    TurnMenuClient *turnMenuClient = dynamic_cast<TurnMenuClient*>(turnMenuClientReceiver);
    ui->turnWidget->setSenderClient(turnMenuClient);
}
Beispiel #3
0
void MainWindow::setupMJ() {
    m_Server = new SwitchServer();

    /* Connect sendMessageToChatUi from m_Server to m_ChatWidget in order to display system messages
     * during the initialization. */
    connect(m_Server, SIGNAL(sendMessageToChatUi(QString)),
            ui->m_ChatWidget, SLOT(receivedMessage(QString))
    );

    // Server Initialization
    m_Server->init();

    // Initialize ChatWidget with the ChatServer
    ChatServer* chatServer = dynamic_cast<ChatServer*>(
                m_Server->getReceiver(TargetCode::CHAT_SERVER));
    ui->m_ChatWidget->setSenderServer(chatServer);

    // Initialize TokenMenu with the TokenMenuServer
    Receiver *tokenMenuServerReceiver = m_Server->getReceiver(TargetCode::TOKEN_MENU_SERVER);
    TokenMenuServer *tokenMenuServer = dynamic_cast<TokenMenuServer*>(tokenMenuServerReceiver);
    ui->tokenPage->setSenderServer(tokenMenuServer);

    // Initialize TurnMenu with the TurnMenuServer
    Receiver *turnMenuServerReceiver = m_Server->getReceiver(TargetCode::TURN_MENU_SERVER);
    TurnMenuClient *turnMenuServer = dynamic_cast<TurnMenuClient*>(turnMenuServerReceiver);
    ui->turnWidget->setSenderClient(turnMenuServer);

    setupPlayer();

    CmdNickname *cmdNickname = dynamic_cast<CmdNickname *>(
        chatServer->getCommands()->getUserCommand(ChatCodes::USERCMD_NICK)
    );
    connect(cmdNickname, SIGNAL(addPlayerToInterface(QString)),
            this, SLOT(addPlayerToInterface(QString)));
}
Beispiel #4
0
void IRCAccount::connect( const Kopete::OnlineStatus& /* initialStatus */ )
{
	kDebug ( 14210 ) ;
	myself()->setOnlineStatus( IRCProtocol::protocol()->ircOnline );
	QObject::connect ( m_server, SIGNAL (messageReceived(QString)),
			this, SLOT (receivedMessage(QString)) );
}
Beispiel #5
0
// ----------------------- Process IO ---------------------------
KGameProcessIO::KGameProcessIO(const QString& name) 
   : KGameIO(), d(new KGameProcessIOPrivate)
{
  qCDebug(GAMES_PRIVATE_KGAME) << ": this=" << this << ", sizeof(this)=" << sizeof(KGameProcessIO);

  //qCDebug(GAMES_PRIVATE_KGAME) << "================= KMEssageServer ====================";
  //d->mMessageServer=new KMessageServer(0,this);
  //qCDebug(GAMES_PRIVATE_KGAME) << "================= KMEssageClient ====================";
  //d->mMessageClient=new KMessageClient(this);
  qCDebug(GAMES_PRIVATE_KGAME) << "================= KMEssageProcessIO ====================";
  d->mProcessIO=new KMessageProcess(this,name);
  qCDebug(GAMES_PRIVATE_KGAME) << "================= KMEssage Add client ====================";
  //d->mMessageServer->addClient(d->mProcessIO);
  //qCDebug(GAMES_PRIVATE_KGAME) << "================= KMEssage SetSErver ====================";
  //d->mMessageClient->setServer(d->mMessageServer);
  qCDebug(GAMES_PRIVATE_KGAME) << "================= KMEssage: Connect ====================";
  //connect(d->mMessageClient, SIGNAL(broadcastReceived(QByteArray,quint32)),
  //        this, SLOT(clientMessage(QByteArray,quint32)));
  //connect(d->mMessageClient, SIGNAL(forwardReceived(QByteArray,quint32,QValueList<quint32>)),
  //        this, SLOT(clientMessage(QByteArray,quint32,QValueList<quint32>)));
  connect(d->mProcessIO, SIGNAL(received(QByteArray)),
          this, SLOT(receivedMessage(QByteArray)));
  // Relay signal
  connect(d->mProcessIO, SIGNAL(signalReceivedStderr(QString)),
          this, SIGNAL(signalReceivedStderr(QString)));
  //qCDebug(GAMES_PRIVATE_KGAME) << "Our client is id="<<d->mMessageClient->id();
}
Beispiel #6
0
void Receiver::processPendingDatagrams()
{
    while (this->udpSocket->hasPendingDatagrams()) {
        QByteArray datagram;
        datagram.resize(udpSocket->pendingDatagramSize());
	this->udpSocket->readDatagram(datagram.data(), datagram.size());

        emit receivedMessage(QString(datagram.data()));

    }
}
// Handle new data from the device
void WirelessHIDDevice::receivedData(void)
{
    IOMemoryDescriptor *data;
    WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider());
    if (device == NULL)
        return;
    
    while ((data = device->NextPacket()) != NULL)
    {
        receivedMessage(data);
        data->release();
    }
}
Beispiel #8
0
void TcpClient::forwardIncomingMessage(void)
{
  Q_D(TcpClient);
  QByteArray msg = d->tcpSocket->readAll();
  QJsonParseError parseError;
  QJsonDocument json = QJsonDocument::fromJson(msg, &parseError);
  if (parseError.error != QJsonParseError::NoError) {
    QVariantMap map;
    map["status"] = "error";
    map["message"] = parseError.errorString();
    json = QJsonDocument::fromVariant(map);
  }
  emit receivedMessage(json);
}
Beispiel #9
0
void Communication::handle_recv_message(QByteArray& msg)
{
    QDataStream stream(&msg, QIODevice::ReadOnly);
    stream.setVersion(QDataStream::Qt_5_0);
    quint32 cmd;
    QString nickname;
    QString message;
    stream >> cmd;
    stream >> nickname;
    stream >> message;

    switch(cmd)
    {
        case Command::KeepAlive:
            // send signal to user model
            emit receivedKeepAlive(nickname);
        break;

        case Command::Message:
            emit receivedMessage(nickname, message);
        break;

        case Command::HostEvent:
            // Received event which will be hosted by
            emit receivedHostEvent(nickname, message);
        break;

        case Command::ParticipateInEvent:
            emit receivedParicipateInEvent(nickname, message);
        break;

        case Command::CallOutEvent:
            emit receivedCallOutEvent(nickname, message);
        break;
    }
}
Beispiel #10
0
void Receiver::parseMessage(QString message, const QHostAddress& address)
{
    QString command = message.left(message.indexOf(" "));
    if (QString::compare(command, CMD::HELLO) == 0)
    {
        message.remove(0, message.indexOf(" ") + 1);
        std::cout << "Received 'HELLO " << message.toStdString() << "' from " << address.toString().toStdString() << std::endl;
        if (message.length() == 0 || message.indexOf(" ") != -1)
        {
            std::cout << "Invalid HELLO!" << std::endl;
            return;
        }
        emit receivedHello(message, address);
    }
    else if (QString::compare(command, CMD::RESPONSE) == 0)
    {
        message.remove(0, message.indexOf(" ") + 1);
        std::cout << "Received 'RESPONSE " << message.toStdString() << "' from " << address.toString().toStdString() << std::endl;
        emit receivedResponse(message, address);
    }
    else if (QString::compare(command, CMD::JOIN) == 0)
    {
        message.remove(0, message.indexOf(" ") + 1);
        std::cout << "Received 'JOIN " << message.toStdString() << "' from " << address.toString().toStdString() << std::endl;
        QString address = message.left(message.indexOf(" "));
        message.remove(0, message.indexOf(" ") + 1);
        QString nickname = message;
        if (address.length() == 0 || nickname.length() == 0)
        {
            std::cout << "Invalid JOIN!" << std::endl;
            return;
        }
        emit receivedJoin(nickname, QHostAddress(address));
    }
    else if (QString::compare(command, CMD::MESSAGE) == 0)
    {
        message.remove(0, message.indexOf(" ") + 1);
        std::cout << "Received 'MESSAGE " << message.toStdString() << "' from " << address.toString().toStdString() << std::endl;
        emit receivedMessage(message, address);
    }
    else if (QString::compare(command, CMD::ACCEPTED) == 0)
    {
        message.remove(0, message.indexOf(" ") + 1);
        std::cout << "Received 'ACCEPTED " << message.toStdString() << "' from " << address.toString().toStdString() << std::endl;
        if (message.length() == 0 || message.indexOf(" ") == -1)
        {
            std::cout << "Invalid ACCEPTED!" << std::endl;
            return;
        }
        emit receivedAccepted(message);
    }
    else if (QString::compare(command, CMD::QUIT) == 0)
    {
        message.remove(0, message.indexOf(" ") + 1);
        std::cout << "Received 'QUIT " << message.toStdString() << "' from " << address.toString().toStdString() << std::endl;
        if (message.length() == 0 || message.indexOf(" ") != -1)
        {
            std::cout << "Invalid QUIT!" << std::endl;
            return;
        }
        emit receivedQuit(QHostAddress(message));
    }
    else if (QString::compare(command, CMD::GET) == 0)
    {
        std::cout << "Received 'GET' from " << address.toString().toStdString() << std::endl;
        emit receivedGet(address);
    }
    else if (QString::compare(command, CMD::KEEPALIVE) == 0)
    {
        std::cout << "Received 'KEEPALIVE' from " << address.toString().toStdString() << std::endl;
        emit receivedKeepalive(address);
    }
    else
    {
        std::cout << "Recieved unknown message '" << message.toStdString() << "'" << std::endl;
        emit receivedUnknownMessage(QString("Received message \"%1\" from %2").arg(message, address.toString()));
    }
}
Beispiel #11
0
void ClientThread::readyRead()
{
    emit receivedMessage(client->readAll());
}