//--------------------------------------------------------------------------------------------------------------------------------------------------- void TerminalTWT::HandlePostUpdate(StringHash , VariantMap &) { static float timeEnterComplete = 0.0f; static float timeEnterStart = 0.0f; NetworkThread::State stateThread = thread.GetState(); if(stateThread == NetworkThread::DownloadFiles) { if(stateWindow == StateWindow::Start) { MakeWindow(StateWindow::UpdateInProcess); } else { progressBar->SetBytes(thread.GetBytesAll(), thread.GetBytesRecieved()); progressBar->SetParameters(thread.GetPercents() / 100.0f, thread.GetPassedTime(), thread.GetElapsedTime(), thread.GetSpeed(), thread.GetCurrentFile()); } } else if(stateThread == NetworkThread::ConnectClose) { if(stateWindow != StateWindow::UpdateComplete) { MakeWindow(StateWindow::UpdateComplete); WinExec("run.exe -client -address:188.120.239.61 -port:30000", 1); engine_->Exit(); } } }
void Listener<SocketType>::BeginAccept() { NetworkThread<SocketType> *worker = SelectWorker(); SocketType *socket = worker->CreateSocket(); m_acceptor.async_accept(socket->GetAsioSocket(), [this,worker,socket](const boost::system::error_code &ec) { this->OnAccept(worker, socket, ec); }); }
int main(int argc, char **argv) { WSADATA wsaData; WSAStartup(MAKEWORD(2, 2), &wsaData); loadTests(); gInstructionTable.initialise(); NetworkThread thread; auto socket = new Socket(); auto ip = "0.0.0.0"; auto port = "8008"; // On socket error socket->addErrorListener([](Socket *socket, int code) { std::cout << "Listen Socket Error: " << code << std::endl; }); socket->addDisconnectListener([](Socket *socket) { std::cout << "Listen Socket Disconnected" << std::endl; }); // On socket connected, accept pls socket->addAcceptListener([&thread](Socket *socket) { auto newSock = socket->accept(); if (!newSock) { std::cout << "Failed to accept new connection" << std::endl; return; } else { std::cout << "New Connection Accepted" << std::endl; } gTestServers.emplace_back(new TestServer(socket)); thread.addSocket(newSock); }); // Start server if (!socket->listen(ip, port)) { std::cout << "Error starting connect!" << std::endl; return 0; } // Run network thread in main thread std::cout << "Listening on " << ip << ":" << port << std::endl; thread.addSocket(socket); thread.start(); WSACleanup(); return 0; }
//--------------------------------------------------------------------------------------------------------------------------------------------------- void TerminalTWT::Stop() { engine_->DumpResources(true); gLog->Write(0, "out"); gLog->Close(); thread.Stop(); }
Socket::Socket( NetworkManager& socketMrg, NetworkThread& owner ) : m_manager(socketMrg), m_owner(owner), m_socket(owner.service()), m_OutBufferSize(protocol::SEND_BUFFER_SIZE), m_OutActive(false), m_closing(true), m_Address(UNKNOWN_NETWORK_ADDRESS) { }
//--------------------------------------------------------------------------------------------------------------------------------------------------- void TerminalTWT::Start() { gLog = new Log(context_); gLog->SetLevel(Urho3D::LOG_INFO); gLog->Open("launcher.log"); gGraphics = GetSubsystem<Graphics>(); CreateUI(); MakeWindow(StateWindow::Start); SubscribeToEvents(); gContext = context_; CreateListFiles(); thread.Run(); thread.SetPriority(2); }
Socket::Socket(NetworkManager& manager, NetworkThread& owner) : manager_(manager), owner_(owner), socket_(owner.service()), outgoing_buffer_size_(protocol::SEND_BUFFER_SIZE), address_(UNKNOWN_NETWORK_ADDRESS), write_operation_(false), closed_(true) { }