-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcpclient.cpp
49 lines (43 loc) · 941 Bytes
/
tcpclient.cpp
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
#include "tcpclient.h"
#include <QDebug>
TcpClient::TcpClient(QHostAddress host, quint16 port) :
QTcpSocket()
{
connected = false;
connectToHost(host,port);
connect((QAbstractSocket*)this,SIGNAL(connected()),
this,SLOT(connection()));
connect((QAbstractSocket*)this,SIGNAL(disconnected()),
this,SLOT(disconnection()));
connect((QAbstractSocket*)this,SIGNAL(readyRead()),
this,SLOT(reading()));
}
void TcpClient::connection()
{
qDebug()<<"connection";
connected = true;
//write("***");
}
void TcpClient::disconnection()
{
connected = false;
qDebug()<<"disconnection";
}
void TcpClient::reading()
{
QByteArray msg;
msg = readAll();
if (connected)
{
qDebug()<<"reading"<<msg;
emit recieve(msg);
}
}
void TcpClient::send(QByteArray msg)
{
if (connected)
{
write(msg);
qDebug()<<"send"<<msg;
}
}