示例#1
0
文件: client.cpp 项目: lukitree/Chat
void Client::on_sendButton_clicked()
{
	QString message = ui.messageEdit->text();
	ui.messageEdit->clear();

	blockSize = 0;

	if (!message.isEmpty())
	{
		if (message.at(0) == '/')
		{
			sendUserCommand(message);
		}
		else
		{
			QByteArray msg;
			QDataStream out(&msg, QIODevice::WriteOnly);
			out.setVersion(QDataStream::Qt_4_0);

			out << message;

			tcpSocket->write(msg);
		}
	}
}
void ConfigWidget::makeConnections()
{
    // networkPage Connections
    connect(networkPage, SIGNAL(ipChanged(QString)), udpClient, SLOT(setOtherNodeAddress(QString)));
    connect(networkPage, SIGNAL(portChanged(int)), udpClient, SLOT(setOtherNodePort(int)));

    // settingsPage Connections
    connect(settingsPage, SIGNAL(connectClicked()), udpClient, SLOT(startSocket()));
    connect(settingsPage, SIGNAL(sendClicked(QString)), udpClient, SLOT(sendUserCommand(QString)));
    connect(settingsPage, SIGNAL(disconnectClicked()), udpClient, SLOT(stopSocket()));
    connect(settingsPage, SIGNAL(configFileSelected(QString)), ConfigFileHandler::instance(), SLOT(handleFile(QString)));

    // consolePage Connections
    connect(consolePage, SIGNAL(startClicked()), this, SLOT(startConsoleStream()));
    connect(consolePage, SIGNAL(stopClicked()), this, SLOT(stopConsoleStream()));

    // ConfigFileHandler Connections
    connect(ConfigFileHandler::instance(), SIGNAL(commandFromFile(QString)), udpClient, SLOT(sendUserCommand(QString)));

    // udpClient Connection
    connect(udpClient, SIGNAL(dataReplyReceived(QString)), settingsPage, SLOT(addToViewer(QString)));
    connect(udpClient, SIGNAL(connectionChanged(bool)), networkPage, SLOT(adjustToConnection(bool)));
    connect(udpClient, SIGNAL(connectionChanged(bool)), settingsPage, SLOT(adjustToConnection(bool)));
    connect(udpClient, SIGNAL(connectionChanged(bool)), consolePage, SLOT(adjustToConnection(bool)));
}
void dmtcp::DmtcpCoordinatorAPI::connectAndSendUserCommand(char c, int* result /*= NULL*/)
{
  if ( tryConnectToCoordinator() == false ) {
    *result = ERROR_COORDINATOR_NOT_FOUND;
    return;
  }
  sendUserCommand(c,result);
  _coordinatorSocket.close();
}