The value of envio after call writeDatagram is 12. Is wireshark the message is send, but never response.
I move the connect and still the same.
This is the new senderreceive.cpp
#include "sendreceive.h"
#include "ui_sendreceive.h"
#include "QUdpSocket"
#include "QMessageBox"
#include "QDebug"
int sebindeo;
SendReceive
::SendReceive(QWidget *parent
) : ui(new Ui::SendReceive)
{
ui->setupUi(this);
sebindeo = socket->bind(7777);
connect(socket, SIGNAL(readyRead()), this, SLOT(readyReade()));
}
SendReceive::~SendReceive()
{
delete ui;
}
void SendReceive::on_enviarsocket_clicked()
{
qDebug() << "on_enviarsocket_clicked Call";
/*QMessageBox *mensaje = new QMessageBox(this);
mensaje->setWindowTitle(QString("Socket send"));
mensaje->setText(QString("Socket Send, wait..."));
mensaje->addButton(QString("Ok"), QMessageBox::YesRole);
mensaje->exec();*/
Data += "SAMP";
Data
+= QChar(7777 & 0xFF
);
Data
+= QChar(7777 >>
8 & 0xFF
);
Data += 'i';
int envio
= socket
->writeDatagram
(Data,
QHostAddress("93.119.26.214"),
7777);
qDebug() << "Bind: " << sebindeo << "; writeDatagram: " << envio << "; Data: " << Data;
}
void SendReceive::readyReade()
{
qDebug() << "readyReade Call";
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"
int sebindeo;
SendReceive::SendReceive(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SendReceive)
{
ui->setupUi(this);
socket = new QUdpSocket(this);
sebindeo = socket->bind(7777);
connect(socket, SIGNAL(readyRead()), this, SLOT(readyReade()));
}
SendReceive::~SendReceive()
{
delete ui;
}
void SendReceive::on_enviarsocket_clicked()
{
qDebug() << "on_enviarsocket_clicked Call";
/*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 += QChar( 93 );
Data += QChar( 119 );
Data += QChar( 26 );
Data += QChar( 214 );
Data += QChar(7777 & 0xFF);
Data += QChar(7777 >> 8 & 0xFF);
Data += 'i';
int envio = socket->writeDatagram(Data, QHostAddress("93.119.26.214"), 7777);
qDebug() << "Bind: " << sebindeo << "; writeDatagram: " << envio << "; Data: " << Data;
}
void SendReceive::readyReade()
{
qDebug() << "readyReade Call";
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
In php, with the same message and ip:port the server response.
this is the php code:
<?php
/*
* Let's generate the string needed for the packet.
*/
$sIPAddr = "93.119.26.214"; // IP address of the server
$iPort = 7777; // Server port.
$sPacket = ""; // Blank string for packet.
$aIPAddr = explode('.', $sIPAddr); // Exploding the IP addr.
$sPacket .= "SAMP"; // Telling the server it is a SA-MP packet.
$sPacket .= chr($aIPAddr[0]); //
$sPacket .= chr($aIPAddr[1]); //
$sPacket .= chr($aIPAddr[2]); //
$sPacket .= chr($aIPAddr[3]); // Sending off the server IP,
$sPacket .= chr($iPort & 0xFF); //
$sPacket .= chr($iPort >> 8 & 0xFF); // Sending off the server port.
$sPacket .= 'i'; // The opcode that you want to send.
// You can now send this to the server.
/**
* Let's connect now to the server.
*/
$rSocket = fsockopen('udp://'.$sIPAddr, $iPort, $iError, $sError, 2); // Create an active socket.
fwrite($rSocket, $sPacket); //Send data
print_r(fread($rSocket, 1024));
/* fread($rSocket, 11);
$aDetails['password'] = ord(fread($rSocket, 1));
$aDetails['players'] = ord(fread($rSocket, 2));
$aDetails['maxplayers'] = ord(fread($rSocket, 2));
$iStrlen = ord(fread($rSocket, 4));
$aDetails['hostname'] = fread($rSocket, $iStrlen);
$iStrlen = ord(fread($rSocket, 4));
$aDetails['gamemode'] = fread($rSocket, $iStrlen);
$iStrlen = ord(fread($rSocket, 4));
$aDetails['mapname'] = fread($rSocket, $iStrlen);
print_r($aDetails); */ // Get the output from the server
fclose($rSocket); // Close the connection
?>
<?php
/*
* Let's generate the string needed for the packet.
*/
$sIPAddr = "93.119.26.214"; // IP address of the server
$iPort = 7777; // Server port.
$sPacket = ""; // Blank string for packet.
$aIPAddr = explode('.', $sIPAddr); // Exploding the IP addr.
$sPacket .= "SAMP"; // Telling the server it is a SA-MP packet.
$sPacket .= chr($aIPAddr[0]); //
$sPacket .= chr($aIPAddr[1]); //
$sPacket .= chr($aIPAddr[2]); //
$sPacket .= chr($aIPAddr[3]); // Sending off the server IP,
$sPacket .= chr($iPort & 0xFF); //
$sPacket .= chr($iPort >> 8 & 0xFF); // Sending off the server port.
$sPacket .= 'i'; // The opcode that you want to send.
// You can now send this to the server.
/**
* Let's connect now to the server.
*/
$rSocket = fsockopen('udp://'.$sIPAddr, $iPort, $iError, $sError, 2); // Create an active socket.
fwrite($rSocket, $sPacket); //Send data
print_r(fread($rSocket, 1024));
/* fread($rSocket, 11);
$aDetails['password'] = ord(fread($rSocket, 1));
$aDetails['players'] = ord(fread($rSocket, 2));
$aDetails['maxplayers'] = ord(fread($rSocket, 2));
$iStrlen = ord(fread($rSocket, 4));
$aDetails['hostname'] = fread($rSocket, $iStrlen);
$iStrlen = ord(fread($rSocket, 4));
$aDetails['gamemode'] = fread($rSocket, $iStrlen);
$iStrlen = ord(fread($rSocket, 4));
$aDetails['mapname'] = fread($rSocket, $iStrlen);
print_r($aDetails); */ // Get the output from the server
fclose($rSocket); // Close the connection
?>
To copy to clipboard, switch view to plain text mode
the ip is convert to ascii characters
Bookmarks