123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "ptsocket.h"
-
-
- PTSocket::PTSocket(QObject* p) : QTcpSocket(p)
- {
- m_hasHandshaked = false;
- m_timeout = 5000;
- connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(m_handshakeError()));
- connect(this, SIGNAL(readyRead()), this, SLOT(m_readyRead()));
- }
-
- int PTSocket::getTimeout() const
- {
- return m_timeout;
- }
-
- QByteArray PTSocket::handshakeData() const
- {
- return "LibPTSocket";
- }
-
- void PTSocket::handshake()
- {
- write(handshakeData());
- }
-
- void PTSocket::setTimeout(int t)
- {
- m_timeout = t;
- }
-
- void PTSocket::m_readyRead()
- {
- if(m_hasHandshaked)
- {
-
- }
- else
- {
- QByteArray handshake = handshakeData();
- if(bytesAvailable() >= handshake.size())
- {
- QByteArray data = read(handshake.size());
- if(data == handshake)
- {
- m_hasHandshaked = true;
- }
- else
- m_handshakeError();
- }
- }
- }
-
- void PTSocket::m_handshakeError()
- {
-
- }
|