Answer the question
In order to leave comments, you need to log in
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);
?>
#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 -= 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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question