void ClientConnection::Update(float deltaTime) { // This is for local communications mode (non networked mode) if (localCommunications_) { // Send the OnConnected event if this is the first time we Update after a Connect if (!localCommunications_OnConnected_Done_) { OnConnected(); localCommunications_OnConnected_Done_=true; } // Process all messages in the buffer if (localClientCommunicationsBuffer_) { localClientCommunicationsBuffer_->SetPosition(0); while (localClientCommunicationsBuffer_->GetPosition()<localClientCommunicationsBuffer_->GetSize()) { int size=0; localClientCommunicationsBuffer_->Read(&size); OnReceiveData(StaticBuffer(static_cast<unsigned char*>(localClientCommunicationsBuffer_->GetPointer())+localClientCommunicationsBuffer_->GetPosition(),size)); localClientCommunicationsBuffer_->SetPosition(localClientCommunicationsBuffer_->GetPosition()+size); } localClientCommunicationsBuffer_->Clear(false); } } }
bool ClientBase::Update() { Byte buffer[256]; fd_set readset; struct timeval timeout = {0,0}; FD_ZERO(&readset); FD_SET(socket_, &readset); ssize_t ret = select(socket_ + 1, &readset, NULL, NULL, &timeout); if (ret == 0) return true; ret = recv(socket_, buffer, 1, MSG_WAITALL); if (ret != 1) { error_ = "recv length failed."; return false; } Size length = buffer[0]; ret = recv(socket_, buffer, length, MSG_WAITALL); if (ret != length) { error_ = "recv data failed."; return false; } OnReceiveData(buffer, length); if (length >= 3 && (buffer[0] == 0x41 || buffer[0] == 0x42) && buffer[1] == 0xA1) { if (buffer[2] == 0x21) { Address memory_length = (buffer[5] >> 4) + 1; Address offset = (buffer[6] << 8) | buffer[7]; OnReadMemory(offset, buffer + 8, memory_length); } }