Пример #1
1
void WebUser::setSocket(QWebSocket *socket)
{
	socket_ = socket;

	connect(socket_, SIGNAL(connected()), SIGNAL(connected()));
	connect(socket_, SIGNAL(disconnected()), SIGNAL(disconnected()));
	connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
	connect(socket_, SIGNAL(textMessageReceived(QString)), SLOT(onSocketTextMessageReceived(QString)));
}
Пример #2
0
void SettingsEditorForm::connectToHost(QString addr, int port)
{
    if(_socket != nullptr)
    {
        _socket->close();
        _socket->deleteLater();
    }

    _socket = new QSslSocket(this);
    connect( _socket, SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(onSocketError(QAbstractSocket::SocketError)));

    connect( _socket, SIGNAL(peerVerifyError(QSslError)), this, SLOT(onPeerVerifyError(QSslError)) );
    connect( _socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(onSslErrors(QList<QSslError>)));

    connect( _socket, SIGNAL(connected()),this,SLOT(onConnected()));
    connect( _socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));

    _socket->setLocalCertificate( "./certs/manager.crt"  );
    _socket->setPrivateKey( "./certs/manager.key");

    _socket->setProtocol(QSsl::SecureProtocols);

    _socket->setCaCertificates(QSslCertificate::fromPath("./certs/trusted.pem"));

    _socket->connectToHostEncrypted( addr, port, "SettingsServer");

    if(!_socket->waitForEncrypted(1000))
    {
        LoggerDialog::get()->Error("SettingsEditorForm::connectToHost","Wait for encrypted failed!");
        _socket->close();
        ui->pushButton_connect->setText("Connect");
    }
}
/*!
  Initializes the client and connects to \a remoteService.
*/
void BluetoothClient::startClient(const QBluetoothServiceInfo &remoteService)
{
    if (mSocket || mRetries) {
        qDebug() << "BluetoothClient::startClient(): Already running!";
        return;
    }

    mService = remoteService;
    mRetries = NumberOfRetries;
    mLastErrorString = "";

    Common::resetBuffer();

    QBluetoothAddress address = mService.device().address();
    qDebug() << "BluetoothClient::startClient(): Bluetooth address: " << address.toString();

    mSocket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket);
    connect(mSocket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(mSocket, SIGNAL(connected()), this, SLOT(onConnected()));
    connect(mSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
    connect(mSocket, SIGNAL(error(QBluetoothSocket::SocketError)),
            this, SLOT(onSocketError(QBluetoothSocket::SocketError)));

    // mSocket->connectToService() call may block the UI thread. Thus, use the
    // the timer to delay the call in case we want to show some note for the
    // user.
    QTimer::singleShot(RetryInterval, this, SLOT(connectToService()));
}
Пример #4
0
void UDPSocket::onError(const scy::Error& error) 
{        
    ErrorS(this) << "Error: " << error.message << endl;    
    //emitError(error);
    onSocketError(error);
    close(); // close on error
}
Пример #5
0
void AuthHandler::setSocket(QTcpSocket *socket)
{
    _socket = socket;
    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState)));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));
}
Пример #6
0
void Server::onNewConnection() {
    QTcpSocket* client_socket = server->nextPendingConnection();
    connect(client_socket, SIGNAL(readyRead()), this, SLOT(readData()));
    connect(client_socket, SIGNAL(disconnected()), this, SLOT(onSocketDisconnected()));
    connect(client_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));

    printReport(tr("%1: User connected").arg(client_socket->socketDescriptor()));
}
Пример #7
0
Tcp::Tcp(QObject *parent) :
    QObject(parent)
{
    stream.setVersion(QDataStream::Qt_4_8);
    socket=new QTcpSocket(this);
    if(!socket)
        qDebug()<<__FUNCTION__<<"error";
    connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(onSocketError(QAbstractSocket::SocketError)));
}
Пример #8
0
void Dialog::setupSignalsAndSlots()
{
    connect(m_socket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
    connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
    connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(m_ui->previewButton, SIGNAL(clicked()), this, SLOT(onPreviewButtonClicked()));
    connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(onButtonBoxClicked(QAbstractButton*)));
    connect(m_ui->serverIpLineEdit, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
}
Пример #9
0
void DesktopUser::setSocket(QTcpSocket *socket)
{
	socket_ = socket;

	connect(socket_, SIGNAL(connected()), SIGNAL(connected()));
	connect(socket_, SIGNAL(disconnected()), SIGNAL(disconnected()));
	connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
	connect(socket_, SIGNAL(readyRead()), SLOT(onSocketReadyRead()));
}
Пример #10
0
void SlimApplication::processNewConnection()
{
    m_clientSocket = m_server->nextPendingConnection();
    connect(m_clientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(onSocketError(QAbstractSocket::SocketError)));
    // Create TCpSlimService?
    SlimService *service = new SlimService(m_clientSocket, m_clientSocket, this);
    connect(m_clientSocket, &QTcpSocket::disconnected,
            service, &SlimService::stop);
    service->start();
}
Пример #11
0
Asterisk::Asterisk(QObject *parent, QString host, quint16 port) :
    QObject(parent),
    host(host),
    port(port)
{
    connect(&socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));
    connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
    connect(&socket, SIGNAL(readyRead()), SLOT(onSocketReadyRead()));

    qDebug("Asterisk Manager initialized");
}
/*! Constructs a coap access manager with the given \a parent and \a port. */
CoapNetworkAccessManager::CoapNetworkAccessManager(QObject *parent, const quint16 &port) :
    QObject(parent),
    m_port(port)
{
    m_socket = new QUdpSocket(this);

    if (!m_socket->bind(QHostAddress::Any, m_port, QAbstractSocket::ShareAddress))
        qCWarning(dcCoap) << "Could not bind to port" << m_port << m_socket->errorString();

    connect(m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
}
Пример #13
0
void FileTransfertUpload::receiveAcceptFile(NetworkClient *client, int port)
{
    if (port == 0) {
        _errors++;
        emit clientError("Client reject file.");
        check_nbr();
    } else {
        QTcpSocket *socket = new QTcpSocket(this);

        socket->connectToHost(client->getTcpSocket()->peerAddress(), port);
        connect(socket, SIGNAL(connected()), this, SLOT(onSocketConnected()));
        connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
        connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(onSocketWritten()));
    }
}
Пример #14
0
void Client::setSocket(QTcpSocket *socket)
{
    this->socket = socket;
    this->socket->setParent(this);

    socketIn.setDevice(socket);
    socketOut.setDevice(socket);

    connect(socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));
    connect(socket, SIGNAL(disconnected()), SIGNAL(socketDisconnected()));
    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
    connect(socket, SIGNAL(readyRead()), SLOT(onSocketReadyRead()));

    initiateHandshake();
    resetHeartbeatTimer();
}
// -----------------------------------------------------------------------------
bool NetworkDeviceController::open()
{
    // set some reasonable default values
    QString address("192.168.1.100");
    int portnum = 8090;

    // was an address specified?
    if (m_device.length())
    {
        // if so, split it into ip address and port number
        QStringList ssplit = m_device.split(":", QString::SkipEmptyParts);
        if (ssplit.size() != 2)
        {
            Logger::err("NetworkDevice: invalid address format (addr:port)\n");
            return false;
        }

        address = ssplit[0];
        portnum = ssplit[1].toInt();
    }
    Logger::info(tr("NetworkDevice: creating network device %1 port %2\n")
            .arg(address).arg(portnum));

    // attempt to create and connect to the network socket
    m_sock = new QTcpSocket();
    connect(m_sock, SIGNAL(readyRead()), this, SLOT(onSocketReadyRead()));
    connect(m_sock, SIGNAL(disconnected()), this, SLOT(onSocketDisconnected()));
    connect(m_sock, SIGNAL(error(QAbstractSocket::SocketError)), this,
            SLOT(onSocketError(QAbstractSocket::SocketError)));

    // attempt to connect to the specified address:port
    m_sock->connectToHost(address, portnum);
    if (!m_sock->waitForConnected(3000)) {
        emit connectionStatusChanged(QString("Connection failed"), false);
        Logger::warn("NetworkDevice: connection timed out\n");
        return false;
    }

    emit connectionStatusChanged(QString("Connected to ") + m_device, true);
    Logger::info(tr("NetworkDevice: connected to ") + m_device + "\n");

    emit flightStateChanged(FCS_STATE_GROUNDED);

    startup();
    return true;
}
Пример #16
0
void MainWindow::on_LaunchClient_clicked()
{
    this->clientSocket = new QLocalSocket(this);
    connect(this->clientSocket, SIGNAL(disconnected()), this->clientSocket, SLOT(deleteLater()));
    connect(this->clientSocket, SIGNAL(readyRead()), this, SLOT(onReadFromServer()));
    connect(this->clientSocket, SIGNAL(error(QLocalSocket::LocalSocketError)),
                        this, SLOT(onSocketError(QLocalSocket::LocalSocketError)));
    this->clientSocket->connectToServer("testlocalsocket");

    auto sendCount = qrand() % 20;
    for (int i = 0; i < sendCount; i++) {
        this->ui->Log->appendPlainText(QString("Writing '%1'").arg(i));
        this->clientSocket->write((QString::number(i) + "\n").toUtf8());
    }
    this->clientSocket->write("end\n");
    this->clientSocket->flush();
}
Пример #17
0
void MainWindow::onConnected()
{
    this->ui->Log->appendPlainText("Connected from Client\n");
    this->serverSocket = this->server->nextPendingConnection();
    connect(this->serverSocket, SIGNAL(disconnected()), this->serverSocket, SLOT(deleteLater()));
    connect(this->serverSocket, SIGNAL(readyRead()), this, SLOT(onReadFromClient()));
    connect(this->serverSocket, SIGNAL(error(QLocalSocket::LocalSocketError)),
                        this, SLOT(onSocketError(QLocalSocket::LocalSocketError)));

    auto sendCount = qrand() % 20;
    for (int i = 0; i < sendCount; i++) {
        this->ui->Log->appendPlainText(QString("Writing '%1'").arg(i));
        this->serverSocket->write((QString::number(i) + "\n").toUtf8());
    }
    this->serverSocket->write("end\n");
    this->serverSocket->flush();
}
Пример #18
0
DefaultConnection::DefaultConnection(IConnectionPlugin *APlugin, QObject *AParent) : QObject(AParent)
{
	FPlugin = APlugin;

	FSrvQueryId = START_QUERY_ID;
	connect(&FDns, SIGNAL(resultsReady(int, const QJDns::Response &)),SLOT(onDnsResultsReady(int, const QJDns::Response &)));
	connect(&FDns, SIGNAL(error(int, QJDns::Error)),SLOT(onDnsError(int, QJDns::Error)));
	connect(&FDns, SIGNAL(shutdownFinished()),SLOT(onDnsShutdownFinished()));

	FSocket.setProtocol(QSsl::AnyProtocol);
	connect(&FSocket, SIGNAL(connected()), SLOT(onSocketConnected()));
	connect(&FSocket, SIGNAL(encrypted()), SLOT(onSocketEncrypted()));
	connect(&FSocket, SIGNAL(readyRead()), SLOT(onSocketReadyRead()));
	connect(&FSocket, SIGNAL(modeChanged(QSslSocket::SslMode)), SIGNAL(modeChanged(QSslSocket::SslMode)));
	connect(&FSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
	connect(&FSocket, SIGNAL(sslErrors(const QList<QSslError> &)), SLOT(onSocketSSLErrors(const QList<QSslError> &)));
	connect(&FSocket, SIGNAL(disconnected()), SLOT(onSocketDisconnected()));

	FConnectTimer.setSingleShot(true);
	FConnectTimer.setInterval(CONNECT_TIMEOUT);
	connect(&FConnectTimer,SIGNAL(timeout()),SLOT(onConnectTimerTimeout()));
}
Пример #19
0
void TCPSocket::onError(const scy::Error& error) 
{        
    DebugLS(this) << "Error: " << error.message << endl;
    onSocketError(error);
    close(); // close on error
}
Пример #20
0
void HMI_Client::connectToServer(QString hostName, int portNumber)
{
    socket->connectToHost(hostName, portNumber);
    connect(this->socket, SIGNAL(connected()), this, SLOT(onConnected()));
    connect(this->socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
}
Пример #21
0
MessageView::MessageView(ViewInfo::Type type, IrcConnection* connection, IrcChannelStackView* stackView) :
	QWidget(stackView)
{
	d.setupUi(this);
	d.viewType = type;
	d.sentId = 1;
#if QT_VERSION >= 0x040700
	d.awayReply.invalidate();
#else
	d.awayReply = QTime();
#endif
	d.playback = false;
	d.parser = stackView->parser();
	d.firstNames = true;
	d.messageTimer = new QTimer(this);
	connect(d.messageTimer, SIGNAL(timeout()), this, SLOT(sendMessageLine()));

	d.joined = 0;
	d.parted = 0;
	d.connected = 0;
	d.disconnected = 0;

	d.chatInput = new CWidgetChatInput(this, true);
	d.verticalLayoutInputWidget->addWidget(d.chatInput);
	d.widgetInput->setFixedHeight(130);
	d.chatInput->setFixedHeight(130);

	connect(d.splitter, SIGNAL(splitterMoved(int, int)), this, SLOT(onSplitterMoved()));

	setFocusProxy(d.chatInput->textEdit());
	d.textBrowser->setBuddy(d.chatInput->textEdit());
	d.textBrowser->viewport()->installEventFilter(this);
	connect(d.textBrowser, SIGNAL(anchorClicked(QUrl)), SLOT(onAnchorClicked(QUrl)));

	d.highlighter = new SyntaxHighlighter(d.textBrowser->document());

	d.connection = connection;
	connect(d.connection, SIGNAL(statusChanged(IrcConnection::Status)), this, SLOT(onConnectionStatusChanged()));

	if (type == ViewInfo::Server)
		connect(d.connection, SIGNAL(socketError(QAbstractSocket::SocketError)), this, SLOT(onSocketError()));

	d.topicLabel->setVisible(type == ViewInfo::Channel);
	d.listView->setVisible(type == ViewInfo::Channel);
	if (type == ViewInfo::Channel) {
		d.listView->setConnection(connection);
		connect(d.listView, SIGNAL(queried(QString)), this, SIGNAL(queried(QString)));
		connect(d.listView, SIGNAL(doubleClicked(QString)), this, SIGNAL(queried(QString)));
		connect(d.listView, SIGNAL(commandRequested(IrcCommand*)), d.connection, SLOT(sendCommand(IrcCommand*)));
		connect(d.topicLabel, SIGNAL(edited(QString)), this, SLOT(onTopicEdited(QString)));
	} else if (type == ViewInfo::Server) {
Пример #22
0
void MainWindow::on_connectButton_clicked()
{
    if(m_connectionState == ConnectionState::Disconnected)
    {
        QString host = ui->hostLineEdit->text();
        quint16 port = ui->portSpinBox->value();
        QString name = ui->nameLineEdit->text();

        m_tcpClient.reset(new nc::TcpClient);
        m_gameState.reset(new GameState(host, port, name, *m_tcpClient.get()));

        connect(m_tcpClient.get(), SIGNAL(messageRead(QByteArray)), m_gameState.get(), SLOT(onInboundMessage(QByteArray)));
        connect(m_gameState.get(), SIGNAL(outboundMessage(QByteArray)), m_tcpClient.get(), SLOT(writeMessage(QByteArray)));
        connect(m_gameState.get(), SIGNAL(chatMessageReceived(QString)), this, SLOT(onChatMessageReceived(QString)));
        connect(m_gameState.get(), SIGNAL(disconnectedFromServer(QString)), this, SLOT(onDisconnected(QString)));
        connect(this, SIGNAL(chatMessageSent(QString)), m_gameState.get(), SLOT(onChatMessageSent(QString)));
        connect(m_tcpClient.get(), SIGNAL(connected()), this, SLOT(onConnected()));
        connect(m_tcpClient.get(), SIGNAL(disconnected()), this, SLOT(onDisconnected()));
        connect(m_tcpClient.get(), SIGNAL(socketError(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));

        m_tcpClient->connectToHost(host, port);
        changeConnectionState(ConnectionState::Connecting);

        qDebug() << "Connecting.";
        appendHtml(QString("<b>Connecting to %1:%2.</b><br>").arg(host).arg(port));
    }
    else
    {
        m_tcpClient->disconnectFromHost();
    }
}
Пример #23
0
void QTwitchChat::connect()
{
    if( channelName_ == "" )
        return;

    if( isShowSystemMessages() )
        emit newMessage( new QChatMessage( TWITCH_SERVICE, TWITCH_USER, "Connecting to " + channelName_ + "...", "", this ) );

    if( socket_)
    {
        if( socket_->state() == QAbstractSocket::ConnectedState )
            return;
        /*else
            reconnect();*/
    }

    socket_ = new QTcpSocket();

    QObject::connect( socket_, SIGNAL( connected() ), this, SLOT( onConnected() ) );
    QObject::connect( socket_, SIGNAL( readyRead() ), this, SLOT( parseMessage() ) );
    QObject::connect( socket_, SIGNAL( error( QAbstractSocket::SocketError ) ), this, SLOT( onSocketError() ) );

    //QObject::connect( socket_, SIGNAL( disconnected() ), this, SLOT( reconnect() ) );

    socket_->connectToHost( DEFAULT_TWITCH_CHAT_HOST_NAME, DEFAULT_TWITCH_CHAT_PORT_NUMBER );
}
Пример #24
0
void Client::onConnectToServer(QHostAddress address, qint16 port, QString name)
{
	ClientRoom* newClientRoom = new ClientRoom(name, address, port);

	connect(newClientRoom->getSocket(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
	connect(newClientRoom->getSocket(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), newClientRoom, SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
	connect(newClientRoom, SIGNAL(socketStateChanged(QAbstractSocket::SocketState)), this, SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
	connect(newClientRoom, SIGNAL(sendTypedMessage(QString)), this, SLOT(onSendTypedMessage(QString)));
	newClientRoom->connect();
}
Пример #25
0
void ServerListener::hasNewConn()
{
    while(MainServer->hasPendingConnections())
    {
        for(int i=0;;i++)
        {
            if(i==MAXCONNECTION)//连接队列已满
            {
                qDebug()<<"MAXCONNECTION";
                MainServer->nextPendingConnection()->close();
                break;
            }
            if(clients[i]==NULL)//添加连接
            {
                clients[i]=MainServer->nextPendingConnection();
                connect(clients[i],SIGNAL(readyRead()),this,SLOT(hasData()));
                connect(clients[i],SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(onSocketError(QAbstractSocket::SocketError)));
                qDebug()<<__FUNCTION__<<"succeed";
                break;

            }
        }
    }
}
Пример #26
0
void            HostedCall::receiveNewTcpConnection()
{
    int             id;
    bool            ok = false;
    QTcpSocket      *sock = this->_tcpServer.nextPendingConnection();
    if (sock != 0)
    {
        std::cout << "Receive new tcp connection" << std::endl;
        QString ip = sock->peerAddress().toString();
        QList<Callee>::iterator it = this->_allowedUser.begin();
        for (; it != this->_allowedUser.end(); ++it)
        {
            if (it->getIp() == ip)
            {
                ok = true;
                it->setSock(sock);
                connect(sock, SIGNAL(readyRead()), &this->_worker, SLOT(onReadSomething()));
                connect(sock, SIGNAL(disconnected()), &this->_worker, SLOT(onClientDisconnectedFromCall()));
                connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));
                id = this->_connectedUsers.count() + 1;
                this->_container.addProducer(id);
                this->sendWelcome(id, sock);
                this->sendParticipantStatusUpdate(true, id, it->getUsername());
                this->sendUdpReady(sock);
                this->_connectedUsers[id] = Callee(it->getIp(), it->getUsername());
                this->_connectedUsers[id].setSock(sock);
                this->_allowedUser.erase(it);
                break;
            }
        }
        if (!ok)
            sock->close();
    }
}