-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmytcpsocket.cpp
More file actions
51 lines (39 loc) · 1.1 KB
/
Copy pathmytcpsocket.cpp
File metadata and controls
51 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "mytcpsocket.h"
MyTcpSocket::MyTcpSocket(QObject *parent) :
QObject(parent)
{
}
void MyTcpSocket::doConnect()
{
socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()),this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
qDebug() << "connecting...";
// this is not blocking call
socket->connectToHost("192.168.0.100", 80);
// we need to wait...
if(!socket->waitForConnected(5000))
{
qDebug() << "Error: " << socket->errorString();
}
}
void MyTcpSocket::connected()
{
qDebug() << "connected...";
}
void MyTcpSocket::disconnected()
{
qDebug() << "disconnected...";
}
void MyTcpSocket::bytesWritten(qint64 bytes)
{
qDebug() << bytes << " bytes written...";
}
void MyTcpSocket::readyRead()
{
qDebug() << "reading...";
// read the data from the socket
qDebug() << socket->readAll();
}