second test
This commit is contained in:
45
udpsender.cpp
Normal file
45
udpsender.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "udpsender.h"
|
||||
|
||||
|
||||
UdpSender::UdpSender(QString IP, quint16 Port)
|
||||
{
|
||||
sock = new QUdpSocket();
|
||||
qDebug() << sock->state();
|
||||
//cout << sock->socketDescriptor() << endl;
|
||||
//qDebug() << sock->socketDescriptor();
|
||||
addr = QHostAddress(IP);
|
||||
port = Port;
|
||||
connect(sock, SIGNAL(readyRead()),this, SLOT(slotRead()));
|
||||
}
|
||||
|
||||
|
||||
UdpSender::~UdpSender()
|
||||
{
|
||||
sock->close();
|
||||
delete sock;
|
||||
}
|
||||
|
||||
|
||||
void UdpSender::slotRead()
|
||||
{
|
||||
QString s;
|
||||
QByteArray * recdata = new QByteArray();
|
||||
*recdata = sock->readAll();
|
||||
s = *recdata;
|
||||
cout << "Received data: ";
|
||||
for (int i = 0; i < s.length(); i++) cout << s[i].toAscii();
|
||||
cout << endl;
|
||||
qDebug() << sock->write(recstr.toUtf8());
|
||||
qDebug() << sock->socketDescriptor();
|
||||
}
|
||||
|
||||
|
||||
void UdpSender::connectSend(QString s)
|
||||
{
|
||||
sz = s.length();
|
||||
sock->connectToHost(addr,port);
|
||||
qDebug() << sock->error();
|
||||
qDebug() << sock->state();
|
||||
qDebug() << sock->socketDescriptor();
|
||||
if (sock->write(s.toUtf8())>0) qDebug() << "writen!";
|
||||
}
|
||||
Reference in New Issue
Block a user