Esempio n. 1
0
///udp process
void ThreadNet::udpProcessMessage(Message::TextMessageStruct *messageStruct)
{
	if(messageStruct->sender.isEmpty() || messageStruct->reciever.isEmpty())
    {
      return;
    }

	if(messageStruct->reciever != GlobalData::settings_struct.profile_key_str)
    {
			if(messageStruct->sender != GlobalData::settings_struct.profile_key_str)
        {
					//no sniffing man!
          return;
        }
      else
        {
					qDebug()<<"@ThreadNet::udpProcessMessage(): Got msg I sent: "<<messageStruct->message;
					emit messageRecieved(messageStruct, true);
        }
    }
  else
    {
			if(messageStruct->sender == GlobalData::settings_struct.profile_key_str)
        {
          qDebug()<<"@ThreadNet::udpProcessMessage(): me 2 me...";
					emit messageRecieved(messageStruct, true);
        }
      else
        {
					qDebug()<<"@ThreadNet::udpProcessMessage(): Other people sent: "<<messageStruct->message;
					emit messageRecieved(messageStruct, false);
        }
    }
}
OutputStreamMonitor::~OutputStreamMonitor()
{
    // output anything that is left
    if (!m_string.empty())
        emit messageRecieved(QString::fromStdString(m_string));
    m_stream.rdbuf(m_oldBuf);
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    // Get the port we will listen on
    QInputDialog options;
    options.setLabelText("Enter port for listening:");
    options.setTextValue("12349");
    options.exec();

    MainWindow window;
    Server server(options.textValue());
    Client client;

    window.connect(&server, SIGNAL(messageRecieved(QString,QString)),
                    &window, SLOT(displayNewMessage(QString,QString)));

    window.connect(&window, SIGNAL(connectToChanged(QString,QString)),
                   &client, SLOT(connectTo(QString,QString)));

    window.connect(&window, SIGNAL(sendMessage(QString)),
                   &client, SLOT(startTransfer(QString)));

    window.show();
    window.resize(480,320);
    window.setWindowTitle(window.windowTitle() + " (listen port: " + options.textValue() + ")");
    
    return a.exec();
}
Esempio n. 4
0
Process::Process(Client *client, QVariant pid) :
    m_client(client),
    m_pid(pid),
    QObject(client)
{
    QObject::connect(m_client, &Client::messageRecieved,
                     [=](QVariant to, QVariant value) {
        if (to == this->m_pid)
            emit messageRecieved(to, value);
    });
}
Esempio n. 5
0
File: test.cpp Progetto: d---/QAMQP
Test::Test() {
	QUrl con(QString("amqp://*****:*****@localhost:5672/"));
	client_ = new QAMQP::Client(this);
	client_->open(con);
	exchange_ =  client_->createExchange("test.test2");
	exchange_->declare("fanout");

	queue_ = client_->createQueue("test.my_queue", exchange_->channelNumber());
	queue_->declare();

	queue2_ = client_->createQueue("test.my_queue2");
	queue2_->declare();

	exchange_->bind(queue_);
	exchange_->bind(queue2_);

	connect(queue2_, SIGNAL(declared()), this, SLOT(declared()));

	connect(queue_, SIGNAL(messageRecieved()), this, SLOT(newMessage()));	
	connect(queue2_, SIGNAL(messageRecieved()), this, SLOT(newMessage()));
}
Esempio n. 6
0
void SingleApplication::newConnection()
{
    QLocalSocket *socket = m_localServer->nextPendingConnection();
    if (!socket)
        return;
    socket->waitForReadyRead();
    QTextStream stream(socket);
    QString message;
    stream >> message;
    emit messageRecieved(message);
    delete socket;
}
Esempio n. 7
0
bool Client::connect(QByteArray name, QByteArray otherNode, QByteArray cookie)
{

    if (name == otherNode)
    {
        qWarning() << "Node and otherNode names are the same";
        return false;
    }

    if(ei_connect_init(m_ec, name.data(), cookie.data(), creation++) < 0)
    {
        qWarning() << "Error initialising Erlang CNode";
        return false;
    }

    QByteArray fullName = otherNode + "@localHost";

    int fd = ei_connect(m_ec, fullName.data());
    if (fd < 0)
    {
        qWarning() << "Error connecting to Erlang Node";
        switch (erl_errno) {
        case EHOSTUNREACH:
            qWarning() << "Host is unreachable";
            break;
        case ENOMEM:
            qWarning() << "Out of Memory";
            break;
        case EIO:
            qWarning() << "IO Error";
            break;
        default:
            qWarning() << "erl_errno code" << fd;
            break;
        }
        return false;
    }

    m_fd = fd;

    m_listener = new MsgListener(fd, this);

    QObject::connect(m_listener, &MsgListener::finished, m_listener, &QObject::deleteLater);

    QObject::connect(m_listener, &MsgListener::messageRecieved,
                     [=](QVariant to, QVariant value) { emit messageRecieved(to, value); });

    m_listener->start();

    return true;
}
std::basic_streambuf<char>::int_type OutputStreamMonitor::overflow(std::basic_streambuf<char>::int_type v)
{
    if (v == '\n')
    {
        emit messageRecieved(QString::fromStdString(m_string));
        fprintf(stdout, "%s", m_string.c_str());
        m_string = "";
        m_string.clear();
    }
    else
        m_string += v;

    return v;
}
void Widget::handleConnection()
{
    Session *session = new Session(tcp_server->nextPendingConnection(), this);
    QThread *session_thread = new QThread(this);

    connect(this, SIGNAL(message(QString)), session, SLOT(sendMessage(QString)));
    connect(this, SIGNAL(done()), session, SLOT(disconnect()));
    connect(session, SIGNAL(messageRecieved(QString)), this, SIGNAL(message(QString)));
    connect(session, SIGNAL(closed()), this, SLOT(clientDisconnected()));

    session->moveToThread(session_thread);

    ui->textBrowser->setText("Client connected!");
}
Esempio n. 10
0
void connectForm::on_buttonConnect_clicked()
{
    int n;
    client->set_username(ui->inputUname->text());
    client->set_port(ui->inputPort->text());
    client->set_hostname(ui->inputIP->text());

    if((n = client->connect_to_server()) == -1)
    {
       // perror("connect");
    }
   // QMessageBox::critical(0, QString("Client"), QString("Connected"));
    QObject::connect(&readThread, SIGNAL(messageRecieved(QString)), window, SLOT(dataRecieved(QString)));
    readThread.setSocket(client->get_sock());
    readThread.start();

    client->set_connect();
    hide();
}
Esempio n. 11
0
std::streamsize OutputStreamMonitor::xsputn(const char* p, std::streamsize n)
{
    m_string.append(p, p + n);

    std::string::size_type pos = 0;
    while (pos != std::string::npos)
    {
        pos = m_string.find('\n');
        if (pos != std::string::npos)
        {
            std::string tmp(m_string.begin(), m_string.begin() + pos);
            emit messageRecieved(QString::fromStdString(tmp));
            m_string = "";
            m_string.clear();
        }
    }

    return n;
}
Esempio n. 12
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    qRegisterMetaType<StateForTimestep>("StateForTimestep&");

    ui->setupUi(this);
    modelController = new FieldModelController();
    udpServer = new UdpServer();
    modeManager = new ModeManager();
    recorder = new Recorder();
    player = new RecordPlayer();

    connect(udpServer, SIGNAL(messageRecieved(QString)),modelController, SLOT(updateState(QString)));

    connect(modelController, SIGNAL(updateScene(StateForTimestep&)),
            modeManager, SLOT(on_updateScene_live(StateForTimestep&)));

    connect(modeManager, SIGNAL(updateScene(StateForTimestep&)),
            ui->rosoFieldWdgt, SLOT(on_updateScene(StateForTimestep&)));

    connect(modelController,SIGNAL(updateScene(StateForTimestep&)),
            recorder, SLOT(on_updateScene(StateForTimestep&)));

    connect(recorder, SIGNAL(recordsUpdated()), this, SLOT(on_recordsUpdated()));

    connect(player,SIGNAL(updateScene(StateForTimestep&)),
            modeManager, SLOT(on_updateScene_replay(StateForTimestep&)));

    connect(player, SIGNAL(recordPlayingFinished()),this,SLOT(on_player_finished()));

    ui->record_ListView->setModel(&recordListModel);
    on_liveMode_radioButton_toggled(true);

    ui->record_ListView->setSelectionMode(QListView::SingleSelection);
}
Esempio n. 13
0
 void Broadcast::load( ) {
     connect(System::instance (),SIGNAL(messageRecieved(Message)), s_brdcst,SLOT(readSignal(Message)));
     start();
     qDebug() << "(ntwk) [Broadcast] Loaded.";
 }
Esempio n. 14
0
void SocketHandler::readyRead(common::JsonSocket* socket) {
    QJsonDocument message = socket->read();
    emit messageRecieved(message);
}
Esempio n. 15
0
void Client::listenerMessage(QVariant to, QVariant value)
{
    emit messageRecieved(to, value);
}