summaryrefslogtreecommitdiff
path: root/pluginRoutingInterfaceTCP/tcpClient.cpp
diff options
context:
space:
mode:
authorSimon Brandner <simon.brandner@partner.bmw.de>2011-07-01 15:06:11 +0200
committerSimon Brandner <simon.brandner@partner.bmw.de>2011-07-01 15:06:11 +0200
commit9d723d9b3918d8c9227b806aa9f016699e234a15 (patch)
tree9ec0170ee232818761a8e6046652bff2be9686b5 /pluginRoutingInterfaceTCP/tcpClient.cpp
parentd61f9cbeeb25c02d73fc99170b1bdf0cc802002f (diff)
parente6ad5d883663688d0e36e9d506aa9a1f1190c47f (diff)
downloadaudiomanager-9d723d9b3918d8c9227b806aa9f016699e234a15.tar.gz
Merge branch 'master' of 10.250.89.137:audiomangenivi
Diffstat (limited to 'pluginRoutingInterfaceTCP/tcpClient.cpp')
-rw-r--r--pluginRoutingInterfaceTCP/tcpClient.cpp62
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);
+}