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