muhuhn
5th April 2015, 14:37
I am trying to write a programm that communicates with a server over the network. the server implementation is given, i can not change it.
the servers IP address is the 141.47.69.35 and the server aplication listens to port 11111. the server answers to the source port of the request. as a protocoll udp is used. the example code works fine for transmitting data to the server. with a network sniffer i can see that the server responds correcly. but the function readPendingDatagrams() is never called. i gues there is anything wrong with the ports, but i really have no more idea...
#include "cmyudp.h"
#include "iostream"
using namespace std;
MyUDP::MyUDP(QObject *parent) : QObject(parent)
{
// initialize port
port = 11111;
// create a QUDP socket
udpReceiveSocket = new QUdpSocket(this);
// creat host ip
hostIp = new QHostAddress("141.47.69.35");
// bind socket
udpReceiveSocket->connectToHost(*hostIp, port, QIODevice::ReadWrite);
// setup receiver calllback function
connect(udpReceiveSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()))
}
void MyUDP::HelloUDP()
{
// create send data
QByteArray Data;
Data.append("Hallo Hilfe!");
udpReceiveSocket->write(Data);
}
void MyUDP::readPendingDatagrams()
{
cout << "received!" << endl;
while (udpReceiveSocket->hasPendingDatagrams()) {
cout << "received!" << endl;
}
}
the servers IP address is the 141.47.69.35 and the server aplication listens to port 11111. the server answers to the source port of the request. as a protocoll udp is used. the example code works fine for transmitting data to the server. with a network sniffer i can see that the server responds correcly. but the function readPendingDatagrams() is never called. i gues there is anything wrong with the ports, but i really have no more idea...
#include "cmyudp.h"
#include "iostream"
using namespace std;
MyUDP::MyUDP(QObject *parent) : QObject(parent)
{
// initialize port
port = 11111;
// create a QUDP socket
udpReceiveSocket = new QUdpSocket(this);
// creat host ip
hostIp = new QHostAddress("141.47.69.35");
// bind socket
udpReceiveSocket->connectToHost(*hostIp, port, QIODevice::ReadWrite);
// setup receiver calllback function
connect(udpReceiveSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()))
}
void MyUDP::HelloUDP()
{
// create send data
QByteArray Data;
Data.append("Hallo Hilfe!");
udpReceiveSocket->write(Data);
}
void MyUDP::readPendingDatagrams()
{
cout << "received!" << endl;
while (udpReceiveSocket->hasPendingDatagrams()) {
cout << "received!" << endl;
}
}