Send a socket to server and this response me immediately (This in php). But in QT, the socket not work...
#include "sendreceive.h"
#include "ui_sendreceive.h"
#include "QUdpSocket"
#include "QMessageBox"
#include "QDebug"
SendReceive
::SendReceive(QWidget *parent
) : ui(new Ui::SendReceive)
{
ui->setupUi(this);
}
SendReceive::~SendReceive()
{
delete ui;
}
void SendReceive::on_enviarsocket_clicked()
{
mensaje
->setWindowTitle
(QString("Socket send"));
mensaje
->setText
(QString("Socket Send, wait..."));
mensaje->exec();
Data += "SAMP";
Data.append("i");
int sebindeo = socket->bind(7777);
int envio
= socket
->writeDatagram
(Data,
QHostAddress("93.119.26.214"),
7777);
qDebug() << "Bind: " << sebindeo << "; Send bytes: " << envio << "; Message send: " << Data;
connect(socket, SIGNAL(readyRead()), this, SLOT(readyReade()));
}
void SendReceive::readyReade()
{
while (socket->hasPendingDatagrams()) {
datagram.resize(socket->pendingDatagramSize());
socket->readDatagram(datagram.data(), datagram.size());
qDebug() << "Message receive: " << datagram.data();
}
}
#include "sendreceive.h"
#include "ui_sendreceive.h"
#include "QUdpSocket"
#include "QMessageBox"
#include "QDebug"
SendReceive::SendReceive(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SendReceive)
{
ui->setupUi(this);
}
SendReceive::~SendReceive()
{
delete ui;
}
void SendReceive::on_enviarsocket_clicked()
{
QMessageBox *mensaje = new QMessageBox(this);
mensaje->setWindowTitle(QString("Socket send"));
mensaje->setText(QString("Socket Send, wait..."));
mensaje->addButton(QString("Ok"), QMessageBox::YesRole);
mensaje->exec();
QByteArray Data; // Message for send
Data += "SAMP";
Data += QString( 93 );
Data += QString( 119 );
Data += QString( 26 );
Data += QString( 214 );
Data += QString(7777 & 0xFF);
Data += QString(7777 >> 8 & 0xFF);
Data.append("i");
socket = new QUdpSocket(this);
int sebindeo = socket->bind(7777);
int envio = socket->writeDatagram(Data, QHostAddress("93.119.26.214"), 7777);
qDebug() << "Bind: " << sebindeo << "; Send bytes: " << envio << "; Message send: " << Data;
connect(socket, SIGNAL(readyRead()), this, SLOT(readyReade()));
}
void SendReceive::readyReade()
{
while (socket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(socket->pendingDatagramSize());
socket->readDatagram(datagram.data(), datagram.size());
qDebug() << "Message receive: " << datagram.data();
}
}
To copy to clipboard, switch view to plain text mode
When press "Ok" i send the socket and the debug: Bind: 1 ; Send bytes: 12 ; Message send: "SAMP]wÖai"
The server should send me a message: SAMP^5zÙi–+City of Angels RP [Happy Hours do 10 level]CoA RP v11.5.2 Los Santos
But, the server not send me anything...
--
What we seek to do is send a message to a server and immediately read the data this server returns me.
Bookmarks