diff --git a/client/controller.cpp b/client/controller.cpp index d6f06d08..93aa4db1 100644 --- a/client/controller.cpp +++ b/client/controller.cpp @@ -44,9 +44,7 @@ void Controller::start(const std::string& _ip, size_t _port, int _bufferMs) { bufferMs = _bufferMs; ip = _ip; - - controlConnection = new ClientConnection(this, ip, _port); - controlConnection->start(); + clientConnection = new ClientConnection(this, ip, _port); controllerThread = new thread(&Controller::worker, this); } @@ -66,15 +64,16 @@ void Controller::worker() while (active_) { + clientConnection->start(); try { RequestMsg requestMsg("serverSettings"); shared_ptr serverSettings(NULL); - while (!(serverSettings = controlConnection->sendReq(&requestMsg, 1000))); + while (!(serverSettings = clientConnection->sendReq(&requestMsg, 1000))); cout << "ServerSettings port: " << serverSettings->port << "\n"; requestMsg.request = "sampleFormat"; - while (!(sampleFormat = controlConnection->sendReq(&requestMsg, 1000))); + while (!(sampleFormat = clientConnection->sendReq(&requestMsg, 1000))); cout << "SampleFormat rate: " << sampleFormat->rate << ", bits: " << sampleFormat->bits << ", channels: " << sampleFormat->channels << "\n"; decoder = new OggDecoder(); @@ -82,14 +81,14 @@ void Controller::worker() { requestMsg.request = "headerChunk"; shared_ptr headerChunk(NULL); - while (!(headerChunk = controlConnection->sendReq(&requestMsg, 1000))); + while (!(headerChunk = clientConnection->sendReq(&requestMsg, 1000))); decoder->setHeader(headerChunk.get()); } RequestMsg timeReq("time"); for (size_t n=0; n<10; ++n) { - shared_ptr reply = controlConnection->sendReq(&timeReq, 2000); + shared_ptr reply = clientConnection->sendReq(&timeReq, 2000); if (reply) { double latency = (reply->received.sec - reply->sent.sec) + (reply->received.usec - reply->sent.usec) / 1000000.; @@ -109,7 +108,7 @@ void Controller::worker() while (active_) { usleep(1000000); - shared_ptr reply = controlConnection->sendReq(&timeReq, 1000); + shared_ptr reply = clientConnection->sendReq(&timeReq, 1000); if (reply) { double latency = (reply->received.sec - reply->sent.sec) + (reply->received.usec - reply->sent.usec) / 1000000.; diff --git a/client/controller.h b/client/controller.h index 49b96df2..ee8bea88 100644 --- a/client/controller.h +++ b/client/controller.h @@ -21,7 +21,7 @@ private: void worker(); std::atomic active_; std::thread* controllerThread; - ClientConnection* controlConnection; + ClientConnection* clientConnection; Stream* stream; int bufferMs; std::string ip; diff --git a/server/serverSession.cpp b/server/serverSession.cpp index 3dad57b3..6451ecd6 100644 --- a/server/serverSession.cpp +++ b/server/serverSession.cpp @@ -65,13 +65,13 @@ bool ServerSession::send(BaseMessage* message) void ServerSession::getNextMessage() { -cout << "getNextMessage\n"; +//cout << "getNextMessage\n"; BaseMessage baseMessage; size_t baseMsgSize = baseMessage.getSize(); vector buffer(baseMsgSize); socketRead(&buffer[0], baseMsgSize); baseMessage.deserialize(&buffer[0]); -cout << "getNextMessage: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ", refers: " << baseMessage.refersTo << "\n"; +//cout << "getNextMessage: " << baseMessage.type << ", size: " << baseMessage.size << ", id: " << baseMessage.id << ", refers: " << baseMessage.refersTo << "\n"; if (baseMessage.size > buffer.size()) buffer.resize(baseMessage.size); socketRead(&buffer[0], baseMessage.size);