diff options
author | Simon Brandner <simon.brandner@partner.bmw.de> | 2011-07-01 15:06:11 +0200 |
---|---|---|
committer | Simon Brandner <simon.brandner@partner.bmw.de> | 2011-07-01 15:06:11 +0200 |
commit | 9d723d9b3918d8c9227b806aa9f016699e234a15 (patch) | |
tree | 9ec0170ee232818761a8e6046652bff2be9686b5 /pluginRoutingInterfaceTCP/tcpClient.cpp | |
parent | d61f9cbeeb25c02d73fc99170b1bdf0cc802002f (diff) | |
parent | e6ad5d883663688d0e36e9d506aa9a1f1190c47f (diff) | |
download | audiomanager-9d723d9b3918d8c9227b806aa9f016699e234a15.tar.gz |
Merge branch 'master' of 10.250.89.137:audiomangenivi
Diffstat (limited to 'pluginRoutingInterfaceTCP/tcpClient.cpp')
-rw-r--r-- | pluginRoutingInterfaceTCP/tcpClient.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pluginRoutingInterfaceTCP/tcpClient.cpp b/pluginRoutingInterfaceTCP/tcpClient.cpp new file mode 100644 index 0000000..b2aefe3 --- /dev/null +++ b/pluginRoutingInterfaceTCP/tcpClient.cpp @@ -0,0 +1,62 @@ +/* + * udpClient.cpp + * + * Created on: Apr 6, 2011 + * Author: blacky + */ + +#include "tcpClient.h" +#include <iostream> + +using namespace std; + +tcpClient::tcpClient(QString serverIP_, int serverPort_) { + serverIP=serverIP_; + serverPort=serverPort_; + QObject::connect(this, SIGNAL(connected()), this, SLOT(sendOut())); +} + +tcpClient::~tcpClient() { + // TODO Auto-generated destructor stub +} + +int tcpClient::connect(int source, int sink) { + + sendBuffer.clear(); + sendBuffer.append(QByteArray::number(MSG_CONNECT)); + sendBuffer.append('#'); + sendBuffer.append(QByteArray::number(source)); + sendBuffer.append('#'); + sendBuffer.append(QByteArray::number(sink)); + if (send()) { + this->waitForReadyRead(CONNECT_TIMEOUT); + return this->readAll().toInt(); + } else { + return -1; + } + +} + +void tcpClient::system_ready() { + + sendBuffer.clear(); + sendBuffer.append(QByteArray::number(SIG_system_ready)); + send(); +} + +bool tcpClient::send() { + QHostAddress adr; + adr.setAddress(serverIP); + this->connectToHost(adr,serverPort); + if (!this->waitForConnected(CONNECT_TIMEOUT)) { + cout<<"No connection"<<endl; + return false; + } else { + cout<<"got connection"<<endl; + return true; + } +} + +void tcpClient::sendOut() { + this->write(sendBuffer); +} |