V
V
vjufvufcgyf2020-09-10 20:12:52
PHP
vjufvufcgyf, 2020-09-10 20:12:52

PHP and QT C++ sockets not connecting, what's the problem?

php code

<?php
    $socket = stream_socket_server("tcp://127.0.0.1:4532", $errno, $errstr);
    echo $errno . $errstr;
    while ($connect = stream_socket_accept($socket, -1)) {
        fread($connect);
        fclose($connect);
        echo "done";
    }
    fclose($socket);
?>


QT C++ main.cpp code
#include <QCoreApplication>
#include <QHostAddress>
#include <QTcpSocket>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QScopedPointer<QTcpSocket> socket(new QTcpSocket());
    socket->connectToHost(QHostAddress::LocalHost, 4532);
    if(socket->waitForConnected(5000) == false) return -1;

    socket->write("12321");

    return a.exec();
}


QT C++ code .pro file
QT -= gui
QT += network

CONFIG += c++11 console
CONFIG -= app_bundle

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
        main.cpp

qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2020-09-10
@IGHOR

Maybe you need it? https://doc.qt.io/qt-5/qtwebsockets-index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question