Вопрос в чем ошибка, клиент не получает сообщение от сервера
Клиент:
MainWindow::MainWindow(QWidget *parent): QWidget(parent){
QTextCodec *codec = QTextCodec::codecForName("cp1251");
QTextCodec *codec2 = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForTr(codec2);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForLocale(codec);
setWindowTitle(tr("EchoUDP клиент"));
m_ptxt = new QTextEdit();
start = new QPushButton(tr("Отправить"));
line = new QLineEdit();
udpSocket = new QUdpSocket();
udpSocket->bind(7,QUdpSocket::ShareAddress);
QVBoxLayout *pvb = new QVBoxLayout;
pvb->addWidget(new QLabel("<h1>EchoUDP Client</h1>"));
pvb->addWidget(m_ptxt);
pvb->addWidget(line);
pvb->addWidget(start);
setLayout(pvb);
connect(start, SIGNAL(clicked()), this, SLOT(startBroadcasting()));
connect(udpSocket,SIGNAL(readyRead()),this,SLOT(answer()));
}
void MainWindow::startBroadcasting(){
QByteArray datagram;
QHostAddress a(QString("127.0.0.1"));
int port = 7;
datagram.append(line->text());
udpSocket->writeDatagram(datagram.data(), datagram.size(),a,port);
}
void MainWindow::answer(){
QByteArray datagram;
QHostAddress a;
quint16 port;
datagram.resize(udpSocket->pendingDatagramSize());
udpSocket->readDatagram(datagram.data(),datagram.size(), &a, &port);
m_ptxt->append(datagram.data());
}
Сервер
MainWindow::MainWindow(quint16 nPort,QWidget *parent): QWidget(parent),m_nNextBlockSize(0){
QTextCodec *codec = QTextCodec::codecForName("cp1251");
QTextCodec *codec2 = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForTr(codec2);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForLocale(codec);
setWindowTitle(tr("EchoUDP сервер"));
mySocket = new QUdpSocket(this);
mySocket->bind(7,QUdpSocket::ShareAddress);
connect(mySocket,SIGNAL(readyRead()),this,SLOT(processPendingDatagrams()));
m_ptxt = new QTextEdit;
m_ptxt->setReadOnly(true);
QVBoxLayout *pvb = new QVBoxLayout;
pvb->addWidget(new QLabel("<h1>EchoUDP Server</h1>"));
pvb->addWidget(m_ptxt);
setLayout(pvb);
}
void MainWindow::processPendingDatagrams(){
while (mySocket->hasPendingDatagrams()){
QByteArray datagram;
QHostAddress a;
quint16 port;
datagram.resize(mySocket->pendingDatagramSize());
mySocket->readDatagram(datagram.data(),datagram.size(),&a,&port);
m_ptxt->append(datagram.data());
mySocket->writeDatagram(datagram.data(),datagram.size(),a,port);
}
}