Now tcp connection is working

parent 856c910b
...@@ -49,20 +49,12 @@ void SkyliveProtocol::startPlugin() ...@@ -49,20 +49,12 @@ void SkyliveProtocol::startPlugin()
void SkyliveProtocol::readFromNetwork() void SkyliveProtocol::readFromNetwork()
{ {
std::cout << "Received From Skylive Serve"; char buffer[50];
QDataStream in(tcpSocket); while(tcpSocket->bytesAvailable())
in.setVersion(QDataStream::Qt_4_0);
if(blockSize == 0)
{ {
if(tcpSocket->bytesAvailable() < (int)sizeof(quint16)) tcpSocket->read(buffer, 50);
return; std::cout << "Received From Skylive Server" << buffer << std::endl;
in >> blockSize;
} }
if(tcpSocket->bytesAvailable() < blockSize)
return;
QString receivedTCP;
in >> receivedTCP;
std::cout << "Received From Skylive Server" << receivedTCP.toStdString() << std::endl;
} }
void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg) void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
...@@ -71,9 +63,8 @@ void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg) ...@@ -71,9 +63,8 @@ void SkyliveProtocol::handle_connect(SKMessage::SKMessage msg)
tcpSocket = new QTcpSocket(this); tcpSocket = new QTcpSocket(this);
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFromNetwork())); connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readFromNetwork()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError))); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(displayError(QAbstractSocket::SocketError)));
blockSize=0;
tcpSocket->abort(); tcpSocket->abort();
tcpSocket->connectToHost("localhost", 8081); tcpSocket->connectToHost("www.skylive.name", 8080);
} }
void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg) void SkyliveProtocol::receiveMessage(SKMessage::SKMessage msg)
......
...@@ -54,7 +54,7 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface ...@@ -54,7 +54,7 @@ class SkyliveProtocol : public QObject, SkylivexPluginInterface
QHash<QString, SKHandlerFunction> _handlers; QHash<QString, SKHandlerFunction> _handlers;
QTcpSocket *tcpSocket; QTcpSocket *tcpSocket;
QNetworkSession *networkSession; QNetworkSession *networkSession;
quint16 blockSize;
public: public:
void startPlugin(); void startPlugin();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment