void ConfigWidget::makeConnections() { // networkPage Connections connect(networkPage, SIGNAL(ipChanged(QString)), udpClient, SLOT(setOtherNodeAddress(QString))); connect(networkPage, SIGNAL(portChanged(int)), udpClient, SLOT(setOtherNodePort(int))); // settingsPage Connections connect(settingsPage, SIGNAL(connectClicked()), udpClient, SLOT(startSocket())); connect(settingsPage, SIGNAL(sendClicked(QString)), udpClient, SLOT(sendUserCommand(QString))); connect(settingsPage, SIGNAL(disconnectClicked()), udpClient, SLOT(stopSocket())); connect(settingsPage, SIGNAL(configFileSelected(QString)), ConfigFileHandler::instance(), SLOT(handleFile(QString))); // consolePage Connections connect(consolePage, SIGNAL(startClicked()), this, SLOT(startConsoleStream())); connect(consolePage, SIGNAL(stopClicked()), this, SLOT(stopConsoleStream())); // ConfigFileHandler Connections connect(ConfigFileHandler::instance(), SIGNAL(commandFromFile(QString)), udpClient, SLOT(sendUserCommand(QString))); // udpClient Connection connect(udpClient, SIGNAL(dataReplyReceived(QString)), settingsPage, SLOT(addToViewer(QString))); connect(udpClient, SIGNAL(connectionChanged(bool)), networkPage, SLOT(adjustToConnection(bool))); connect(udpClient, SIGNAL(connectionChanged(bool)), settingsPage, SLOT(adjustToConnection(bool))); connect(udpClient, SIGNAL(connectionChanged(bool)), consolePage, SLOT(adjustToConnection(bool))); }
Server::Server(QWidget *parent) : QDialog(parent) { InitRawInput(); statusLabel = new QLabel(tr("Click 'Start' to start the UDP server")); startButton = new QPushButton(tr("&Start")); quitButton = new QPushButton(tr("&Quit")); buttonBox = new QDialogButtonBox; buttonBox->addButton(startButton, QDialogButtonBox::ActionRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); //UDPServer initialisation udpServer = new UDPServer(false, this); udpServer->setOtherNodePort(50001); connect(startButton, SIGNAL(clicked()), udpServer, SLOT(startSocket())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(Mapper::instance(), SIGNAL(actionHappened(QString)), udpServer, SLOT(sendControllerAction(QString))); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("UDP Protocol Based Server")); }
void ConnectivityManager::setup(bool v4SettingsChanged, bool v6SettingsChanged) { bool autoDetect4 = SETTING(AUTO_DETECT_CONNECTION) && SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_DISABLED; bool autoDetect6 = SETTING(AUTO_DETECT_CONNECTION6) && SETTING(INCOMING_CONNECTIONS6) != SettingsManager::INCOMING_DISABLED; /*{ if((!autoDetect4 && autoDetectedV4) || (!autoDetect6 && autoDetectedV6) || v4SettingsChanged || v6SettingsChanged) { if(v4SettingsChanged || (SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_ACTIVE_UPNP)) { mapperV4.close(); } if((SETTING(INCOMING_CONNECTIONS6) != SettingsManager::INCOMING_ACTIVE_UPNP) || v6SettingsChanged) { mapperV6.close(); } startSocket(); } else if(SETTING(INCOMING_CONNECTIONS) == SettingsManager::INCOMING_ACTIVE_UPNP && !runningV4) { // previous mappings had failed; try again startMapping(); } }*/ if (v4SettingsChanged || (autoDetectedV4 && !autoDetect4)) { mapperV4.close(); autoDetectedV4 = false; } if (v6SettingsChanged || (autoDetectedV6 && !autoDetect6)) { mapperV6.close(); autoDetectedV6 = false; } if(!autoDetect6 && autoDetectedV6) clearAutoSettings(true, false); if (!autoDetect4 && autoDetectedV4) { clearAutoSettings(false, false); } bool autoDetect = false; if(autoDetect4 || autoDetect6) { if ((!autoDetectedV4 && autoDetect4) || (!autoDetectedV6 && autoDetect6) || autoSettings.empty()) { detectConnection(); autoDetect = true; } } if (!autoDetect && (v4SettingsChanged || v6SettingsChanged)) { startSocket(); } if(!autoDetect4 && SETTING(INCOMING_CONNECTIONS) == SettingsManager::INCOMING_ACTIVE_UPNP && !runningV4) // previous mappings had failed; try again startMapping(false); if(!autoDetect6 && SETTING(INCOMING_CONNECTIONS6) == SettingsManager::INCOMING_ACTIVE_UPNP && !runningV4) // previous mappings had failed; try again startMapping(true); }
virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { switch (event) { case eFE_Initialize: { m_actInfo = *pActInfo; } break; case eFE_Activate: { if (IsPortActive(pActInfo, EIP_Enable)) { if (socketWorking) { endSocket(); } m_bEnabled = true; // try to open port socket port = GetPortInt(pActInfo, EIP_Port); multicast = GetPortString(pActInfo, EIP_Multicast); startSocket(port, multicast); Execute(pActInfo); pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true); } if (IsPortActive(pActInfo, EIP_Disable)) { m_bEnabled = false; endSocket(); pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false); } } break; case eFE_Update: { CTimeValue currTime(gEnv->pTimer->GetCurrTime()); float delay = 0; // processing delay delay -= (currTime-m_lastTime).GetSeconds(); m_lastTime = currTime; // Execute? if (delay <= 0.0f) { Execute(pActInfo); } } break; } }
void ConnectivityManager::setup(bool settingsChanged) { if(BOOLSETTING(AUTO_DETECT_CONNECTION)) { if (!autoDetected) detectConnection(); } else { if(autoDetected || settingsChanged) { if(settingsChanged || (SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_FIREWALL_UPNP)) { MappingManager::getInstance()->close(); } startSocket(); } else if(SETTING(INCOMING_CONNECTIONS) == SettingsManager::INCOMING_FIREWALL_UPNP && !MappingManager::getInstance()->getOpened()) { // previous mappings had failed; try again MappingManager::getInstance()->open(); } } }
void StatusSubscribe::fsmDownStartEvent() { if (m_state == State::Down) { #ifdef QT_DEBUG DEBUG_TAG(1, m_debugName, "Event START"); #endif // handle state change emit fsmDownExited(QPrivateSignal()); fsmTrying(); emit fsmTryingEntered(QPrivateSignal()); // execute actions startSocket(); } }
void ConnectivityManager::setup(bool settingsChanged) { if(BOOLSETTING(AUTO_DETECT_CONNECTION)) { if (!autoDetected) detectConnection(); } else { if(autoDetected || (settingsChanged && (SearchManager::getInstance()->getPort() != SETTING(UDP_PORT) || ConnectionManager::getInstance()->getPort() != SETTING(TCP_PORT) || ConnectionManager::getInstance()->getSecurePort() != SETTING(TLS_PORT) || SETTING(BIND_ADDRESS) != lastBind))) { if(settingsChanged || SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_FIREWALL_UPNP) { UPnPManager::getInstance()->close(); } startSocket(); } else if(SETTING(INCOMING_CONNECTIONS) == SettingsManager::INCOMING_FIREWALL_UPNP && !UPnPManager::getInstance()->getOpened()) { // previous UPnP mappings had failed; try again UPnPManager::getInstance()->open(); } } }
void StatusSubscribe::fsmUpHeartbeatTimeoutEvent() { if (m_state == State::Up) { #ifdef QT_DEBUG DEBUG_TAG(1, m_debugName, "Event HEARTBEAT TIMEOUT"); #endif // handle state change emit fsmUpExited(QPrivateSignal()); fsmTrying(); emit fsmTryingEntered(QPrivateSignal()); // execute actions stopHeartbeatTimer(); stopSocket(); startSocket(); } }
void ConnectivityManager::setup_connections(bool settingsChanged) { try { if (BOOLSETTING(AUTO_DETECT_CONNECTION)) { if (!autoDetected) detectConnection(); } else { if (autoDetected || settingsChanged) { if (settingsChanged || SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_FIREWALL_UPNP) { MappingManager::getInstance()->close(); } startSocket(); } else if (SETTING(INCOMING_CONNECTIONS) == SettingsManager::INCOMING_FIREWALL_UPNP && !MappingManager::getInstance()->getOpened()) { // previous mappings had failed; try again MappingManager::getInstance()->open(); } } } catch (const Exception& e) { dcassert(0); const string l_error = "ConnectivityManager::setup error = " + e.getError(); CFlyServerJSON::pushError(56, l_error); } if (settingsChanged) { if (SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_FIREWALL_UPNP) { test_all_ports(); } } }
void CommunicationManager::run() { AvahiClient *client = NULL; int error; struct timeval tv; /* Allocate main loop object */ if (!(simplePoll = avahi_simple_poll_new())) { LoggerUtil_error(logger, "Failed to create simple poll object.\n"); } else { name = avahi_strdup("Ginga Multimodal Event"); /* Allocate a new client */ client = avahi_client_new(avahi_simple_poll_get(simplePoll), (AvahiClientFlags)0, clientCallback, NULL, &error); /* Check whether creating the client object succeeded */ if (!client) { LoggerUtil_error(logger, "Failed to create client: " << avahi_strerror(error)); } else { // Entra num loop para ficar aceitando conexões e recebendo // um xml em cada conexão estabelecida. startSocket(); /* Run the main loop */ // avahi_simple_poll_loop(simplePoll); } } /* Cleanup things */ if (client) { avahi_client_free(client); } if (simplePoll) { avahi_simple_poll_free(simplePoll); } avahi_free(name); }
int CInVehicle_EmulatorDlg::appStartImplement(ThreadProcInfo *ProcInfoParam) { //start Socket startSocket(); //HANDLE threadHandle[3]; threadHandle[0] = (HANDLE) _beginthreadex(0,0,&Thread_RecvMsg,0,0,0); //test for message communitcate //threadHandle[1] = (HANDLE) _beginthreadex(0,0,&Thread_SendMsg,0,0,0); threadHandle[1] = (HANDLE) _beginthreadex(0,0,&Thread_SendMsg,(LPVOID)ProcInfoParam,0,0); //threadHandle[2] = (HANDLE) _beginthreadex(0,0,&Thread_ReconnectSocket,0,0,0); threadHandle[2] = (HANDLE) _beginthreadex(0,0,&Thread_ReconnectSocket,(LPVOID)ProcInfoParam,0,0); SetThreadPriority(threadHandle[0],THREAD_PRIORITY_NORMAL); SetThreadPriority(threadHandle[1],THREAD_PRIORITY_LOWEST); SetThreadPriority(threadHandle[2],THREAD_PRIORITY_NORMAL); //WaitForMultipleObjects(3, threadHandle, true, INFINITE); //CloseHandle(threadHandle[0]); //CloseHandle(threadHandle[1]); //CloseHandle(threadHandle[2]); return 0; }
int main(int argc, char* argv[]) { //do some system initialation appInitEvents(); databaseInit(); //getVehicleID(&g_VehicleID); startSocket(); sendDatabaseVersion(); //initialize the glut glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(200, 200); glutInitWindowSize(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); glutCreateWindow("Vehicle View"); Init3DEngine(); //create each thread, there are three threads. //now use _beginthreadex to create thread for more flexible // _beginthreadex has more parameter to control the thread HANDLE threadHandle[4]; threadHandle[0] = (HANDLE) _beginthreadex(0,0,&Thread_RecvSensors,0,0,0); threadHandle[1] = (HANDLE) _beginthreadex(0,0,&Thread_DBUpdate,0,0,0); threadHandle[2] = (HANDLE) _beginthreadex(0,0,&Thread_DiffDetRpt,0,0,0); threadHandle[3] = (HANDLE) _beginthreadex(0,0,&Thread_VisualizePreProc,0,0,0); //threadHandle[3] = (HANDLE) _beginthreadex(0,0,&Thread_LookAhead,0,CREATE_SUSPENDED,0); //set thread priority SetThreadPriority(threadHandle[0],THREAD_PRIORITY_NORMAL); //+1 priority SetThreadPriority(threadHandle[1],THREAD_PRIORITY_NORMAL); SetThreadPriority(threadHandle[2],THREAD_PRIORITY_LOWEST); SetThreadPriority(threadHandle[3],THREAD_PRIORITY_NORMAL); //SetThreadAffinityMask(threadHandle[0],0x00000001); //SetThreadAffinityMask(threadHandle[1],0x00000002); //SetThreadAffinityMask(threadHandle[2],0x00000003); //SetThreadAffinityMask(threadHandle[3],0x00000004); glutDisplayFunc(&myDisplay); glutTimerFunc((unsigned int)(1000/FRAME_NUM_PER_SECOND),&myTimer,1); glutKeyboardFunc(&keyboardFunc); glutSpecialFunc(&specialKeyFunc); glutReshapeFunc(&reshapeWindow); glutMouseFunc(&mouseButtonFunc); glutMotionFunc(&mouseMoveFunc); glutMainLoop(); WaitForMultipleObjects(4, threadHandle, true, INFINITE); CloseHandle(threadHandle[0]); CloseHandle(threadHandle[1]); CloseHandle(threadHandle[2]); CloseHandle(threadHandle[3]); delete3DEngine(); WSACleanup(); return 0; }
/*C'tor*/ Server_Sock(){ if( startWSA() ) startSocket(); }
int main(int argc, char *argv[]) { //Check arguments if(argc < 2 || argc > 4) { fprintf(stderr, "Usage: %s NAME [SERVERIP] [PORT]\n", argv[0]); fprintf(stderr, "By default SERVERIP=%s and PORT=%u.\n", DEFAULTIP, DEFAULTPORT); exit(1); } //Make sure we don't mess up the terminal signal(SIGINT, cleanup); signal(SIGTERM, cleanup); signal(SIGABRT, cleanup); #ifndef WIN32 signal(SIGSTOP, cleanup); signal(SIGTSTP, cleanup); #endif unsigned short port = DEFAULTPORT; //p for current players unsigned char i, n, players, bombs, id, mines, p; int sock; struct data *pData = NULL; #ifdef WIN32 WSADATA wsaData; if(WSAStartup(MAKEWORD(2, 0), &wsaData)) { fprintf(stderr, "WSAStartup() failed.\n"); exit(10); } #endif //Validate port if(argc == 4 && !(port = strtoul(argv[3], NULL, 0))) { fprintf(stderr, "Invalid port.\n"); exit(2); } //Check if it's a 7 bit name for(i = 0; argv[1][i]; i++) { if(argv[1][i] < 32 || argv[1][i] > 127) { fprintf(stderr, "Invalid name, only 7-bit characters are allowed.\n"); exit(9); } } //Initialize curses initscr(); noecho(); //Check if it is big enough if(LINES < MINLINES || COLS < MINCOLS ) { endwin(); fprintf(stderr, "Your terminal has to be, at least, %ux%u.\n", MINCOLS, MINLINES); exit(3); } //Try to connect i = startSocket(&sock, argc >= 3? argv[2] : DEFAULTIP, port); if(i) { endwin(); switch(i) { case 1: fprintf(stderr, "The socket could not be created.\n"); exit(4); case 2: fprintf(stderr, "Unable to resolv %s.\n", argc >= 3? argv[2] : DEFAULTIP); exit(5); default: fprintf(stderr, "Unable to connect to %s.\n", argc >= 3? argv[2] : DEFAULTIP); exit(6); } } //Send name and retrieve basic info from the server p = exchangeBasics(sock, &players, &bombs, &mines, &id, argv[1], &pData); //Lost connection if(!p) { endwin(); fprintf(stderr, "Lost connection to the server.\n"); exit(7); } //Copy own name for(i = 0; argv[1][i] && i < 16; i++) { pData[id].name[i] = argv[1][i]; } pData[id].name[i] = 0; //Update own stats pData[id].stats = 1; //Initialize the field unsigned char field[16][16]; for(i = 0; i < 16; i++) { for(n = 0; n < 16; n++) { field[i][n] = 10; } } //Draw the basic interface WINDOW *left, *middle, *right, *bottom, *textBox; if(initializeScreen(&left, &middle, &right, &bottom, &textBox)) { fprintf(stderr, "Out of memory.\n"); exit(8); } drawMiddle(middle, field); drawLeft(left, players, id, bombs, mines, pData); drawRight(right); refresh(); wrefresh(left); wrefresh(middle); wrefresh(right); wrefresh(bottom); wrefresh(textBox); //Play p = game(left, bottom, textBox, middle, sock, id, players, bombs, mines, pData, field); shutdown(sock, 2); #ifdef WIN32 closesocket(sock); #else close(sock); #endif if(!p) { showWinner(bottom, players, pData); } //Close curses endwin(); if(p) { fprintf(stderr, "Lost connection to the server.\n"); } //Close curses delwin(left); delwin(middle); delwin(right); delwin(bottom); delwin(textBox); //Free the memory free(pData); return 0; }