/*! From ConnectionIf. */ void WlanConnection::setConnectAs(ConnectAs connectAs) { qDebug() << "WlanConnection::setConnectAs():" << connectAs; ConnectionIf::setConnectAs(connectAs); onReconnect(); if (connectAs == Server && !mServer) { delete mDiscoveryMgr; mDiscoveryMgr = 0; delete mClient; mClient = 0; startServer(); } else if (connectAs == Client && !mClient) { delete mServer; mServer = 0; startDiscoveryMgr(); startClient(); } else if (connectAs == DontCare) { startDiscoveryMgr(); startServer(); startClient(); } }
int main(int argc, char *argv[]) { // print version, help or run tests if (argc == 2 || argc == 3) { const char *arg = argv[1]; if ( argc == 2 && needsVersion(arg) ) { evaluate("version", NULL); return 0; } else if ( needsHelp(arg) ) { evaluate("help", argc == 3 ? argv[2] : NULL); return 0; #ifdef HAS_TESTS } else if ( needsTests(arg) ) { // Skip the "tests" argument and pass the rest to tests. return startTests(argc - 1, argv + 1); #endif } } if (argc == 1) { // if server hasn't been run yet and no argument were specified // then run this process as server return startServer(argc, argv); } else if (argc == 3 && strcmp(argv[1], "monitor") == 0) { // if first argument is monitor (second is monitor server name/ID) // then run this process as monitor return startMonitor(argc, argv); } else { // if argument specified and server is running // then run this process as client return startClient(argc, argv); } }
int Client::reciever(void *){ std::vector<char> buffer; int recieved; while( connected ){ recieved = recvStr( data->serverSocket, buffer ); if (recieved == 0){ onError("Server closed"); break; }else if (recieved == -1){ onError("Recieve error"); break; } onRecv(buffer); buffer.clear(); } #ifdef _WIN32 closesocket(data->serverSocket); #else close(data->serverSocket); #endif //removeConsoleListener(sender); connected = false; startClient(); return 0; }
int main(int argc, char *argv[]) { int status; printf(".:: Starting Simple UDP Host Discover Server - Cliente ::.\n\n"); status = processArguments(argc, argv); if(status != 0) { fprintf(stderr,"Error al procesar el argumento %i\n",status); return -1; } switch(mode) { case SERVER: startServer(listenIP, listenPort); break; case CLIENT: if(strcmp(listenIP,"0.0.0.0")==0) { printHelp(argv[0],true,"En modo cliente es necesario especificar la IP con -i"); } startClient(listenIP,listenPort); break; case NOT_DEFINE: printHelp(argv[0],true,"Es necesario indicar el modo de operación\n"); break; } return 0; }
bool KSysTrayCmd::start() { // If we have no command we must catching an existing window if ( !command ) { if ( win ) { setTargetWindow( win ); return true; } checkExistingWindows(); if ( win ) { // Window always on top if (onTop) { KWin::setState(win, NET::StaysOnTop); } return true; } errStr = i18n( "No window matching pattern '%1' and no command specified.\n" ) .arg( window ); return false; } // Run the command and watch for its window if ( !startClient() ) { errStr = i18n( "KSysTrayCmd: KShellProcess cannot find a shell." ); clientExited(); return false; } return true; }
int main( const int argc , const char ** argv ) { if( flagSpecified(argc,argv,kFlagLogo) ) displayLogo(); initializeRandomGenerator(); initializeSsl(); // Not the most beautiful piece of initialization code :) if( controllerRequested(argc,argv) ) startController(argc,argv); else if( serverRequested(argc,argv) ) startServer(argc,argv); else if( clientRequested(argc,argv) ) startClient(argc,argv); else if( eventStreamRequested(argc,argv) ) startEventStream(argc,argv); else if( generateHashRequested(argc,argv) ) startGenerateHash(argc,argv); else if( addControllerRequested(argc,argv) ) startAddController(argc,argv); else usage(); cleanupSsl(); cleanupLogger(); return EXIT_SUCCESS; }
StorageClient::StorageClient(std::string pIp, int pPort) { _ip = pIp; _port = pPort; _diskList = new DoubleLinkedList<Disk, short>(); startClient(); std::cout<<"client: '"<<pIp<<":"<<pPort<<"' created. "<<"Connection: "<<(isConnected()?"connected":"disconnected")<<std::endl; }
int main() { SOCKET sock = startClient(20015, "127.0.0.1"); if (sock != INVALID_SOCKET) { startLogging(sock); } return 0; }
void Nushabe::deviceDiscovered(const QBluetoothDeviceInfo &device) { dev_list.push_back(device); qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')' ; if(device.address().toString() == "98:D3:31:60:30:DF") { startClient(); } }
void ClientApp::startNode() { // start the client. if this return false then we've failed and // we shouldn't retry. LOG((CLOG_DEBUG1 "starting client")); if (!startClient()) { m_bye(kExitFailed); } }
JNIEXPORT void JNICALL Java_net_hackcasual_freeciv_NativeHarness_startClient (JNIEnv *je, jobject o) { jmethodID register_buffer = 0; (*je)->GetJavaVM(je, &jvm); env_nh = je; jclass cls = (*env_nh)->GetObjectClass(env_nh, o); native_harness = (*env_nh)->NewGlobalRef(env_nh,o); draw_frame = (*env_nh)->GetMethodID(env_nh, cls, "updateDisplay", "()V"); client_connect = (*env_nh)->GetMethodID(env_nh, cls, "clientConnected", "()V"); measure_text = (*env_nh)->GetMethodID(env_nh, cls, "getTextSize", "(Ljava/lang/String;)I"); render_text = (*env_nh)->GetMethodID(env_nh, cls, "renderString", "(Ljava/lang/String;)I"); update_tileset_progress = (*env_nh)->GetMethodID(env_nh, cls, "updateTilesetProgress", "(Ljava/lang/String;)V"); if (draw_frame == 0) { LOGE("Failed to get updateDisplay"); return; } if (measure_text == 0) { LOGE("Failed to get measureText"); return; } if (render_text == 0) { LOGE("Failed to get renderText"); return; } register_buffer = (*env_nh)->GetMethodID(env_nh, cls, "registerNativeBuffers", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)V"); if (register_buffer == 0) { LOGE("Failed to get registerNativeBuffer"); return; } if (!bufferData) bufferData = fc_malloc(BUFFER_SIZE); // 30 pixels high by 300 width by 2 bytes per pixel incommingBuffer = fc_malloc(30 * 300 * 2); jobject direct_buffer = (*env_nh)->NewDirectByteBuffer(env_nh, bufferData, BUFFER_SIZE); jobject incomming_buffer = (*env_nh)->NewDirectByteBuffer(env_nh, incommingBuffer, BUFFER_SIZE); (*env_nh)->CallVoidMethod(env_nh, native_harness, register_buffer, direct_buffer, incomming_buffer); startClient(); }
static int mainLoop() { // logging to files CFileLogOutputter* fileLog = NULL; if (ARG->m_logFile != NULL) { fileLog = new CFileLogOutputter(ARG->m_logFile); CLOG->insert(fileLog); LOG((CLOG_DEBUG1 "Logging to file (%s) enabled", ARG->m_logFile)); } // create socket multiplexer. this must happen after daemonization // on unix because threads evaporate across a fork(). CSocketMultiplexer multiplexer; // create the event queue CEventQueue eventQueue; // start the client. if this return false then we've failed and // we shouldn't retry. LOG((CLOG_DEBUG1 "starting client")); if (!startClient()) { return kExitFailed; } // run event loop. if startClient() failed we're supposed to retry // later. the timer installed by startClient() will take care of // that. CEvent event; DAEMON_RUNNING(true); EVENTQUEUE->getEvent(event); while (event.getType() != CEvent::kQuit) { EVENTQUEUE->dispatchEvent(event); CEvent::deleteData(event); EVENTQUEUE->getEvent(event); } DAEMON_RUNNING(false); // close down LOG((CLOG_DEBUG1 "stopping client")); stopClient(); updateStatus(); LOG((CLOG_NOTE "stopped client")); if (fileLog) { CLOG->remove(fileLog); delete fileLog; } return kExitSuccess; }
void CClientApp::handleClientRestart(const CEvent&, void* vtimer) { // discard old timer CEventQueueTimer* timer = reinterpret_cast<CEventQueueTimer*>(vtimer); EVENTQUEUE->deleteTimer(timer); EVENTQUEUE->removeHandler(CEvent::kTimer, timer); // reconnect startClient(); }
void ClientApp::handleClientRestart(const Event&, void* vtimer) { // discard old timer EventQueueTimer* timer = static_cast<EventQueueTimer*>(vtimer); m_events->deleteTimer(timer); m_events->removeHandler(Event::kTimer, timer); // reconnect startClient(); }
int main() { startClient(); clientLoggin(); pthread_t listeningT, readCMD; pthread_create(&listeningT, NULL,(void *)listening, NULL); pthread_create(&readCMD, NULL, (void *)readCommand, NULL); pthread_join(listeningT, NULL); pthread_join(readCMD, NULL); return 0; }
//! [socketDisconnected] void RfCommClient::socketDisconnected() { // Note: it seems that the "disconnected" signal is not emitted by the socket, so this never gets called qDebug() << __PRETTY_FUNCTION__ << "Got socketDisconnected"; emit disconnected(); stopClient(); // now reconnect and send text string startClient(serviceInfo); connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendText())); lagTimer.start(); }
void SceneGame::addCtrlPanel() { Menu* menu = Menu::create(); this->addChild(menu); LayerColor* bg = LayerColor::create(Color4B(150, 80, 50, 255), winSize.width, winSize.height); addChild(bg, -1); bg->setGlobalZOrder(-300); MenuItemImage *regretItem = MenuItemImage::create("regret.jpg", "regret.jpg" , CC_CALLBACK_1(SceneGame::Regret,this)); menu->addChild(regretItem); moveNode(regretItem, Vec2(160, 60)); MenuItem* startServerItem = MenuItemFont::create("StartServer",CC_CALLBACK_1(SceneGame::startServer,this)); menu->addChild(startServerItem); moveNode(startServerItem, Vec2(160, 0)); MenuItem* startClientItem = MenuItemFont::create("StartClient",CC_CALLBACK_1(SceneGame::startClient,this)); menu->addChild(startClientItem); moveNode(startClientItem, Vec2(160, -60)); startServerItem->setUserObject(startClientItem); startClientItem->setUserObject(startServerItem); MenuItem* restartItem = MenuItemFont::create("Restart", CC_CALLBACK_1(SceneGame::Restart,this)); menu->addChild(restartItem); moveNode(restartItem, Vec2(160, -120)); if (_bRestart) { startServerItem->setEnabled(false); startClientItem->setEnabled(false); NetBattle::clear(); if (_bRedSide) { startServer(startServerItem); } else { startClient(startClientItem); } } }
void BtsSpawnClient::procFinished(int exitCode) { p->forceKillTimer->stop(); emit clientExited(); qDebug() << "btsync finished with code" << exitCode; if(exitCode != 0 || p->autorestart) { QTimer::singleShot(1000, this, SLOT(startClient())); } }
void BtsSpawnClient::restartClient() { if(!p->clientProc) { startClient(); } else { connect(p->clientProc.data(), SIGNAL(finished(int)), this, SLOT(startClient())); exitClient(); } }
/************************************* Deze functie behandelt 1 wagen dat aan het laden is. *************************************/ void *doeiets(void* erin){ struct arg input=*((struct arg *)erin); int error, socket2; char *tekst=malloc(tekstlengte*sizeof(char)); void *buffer=malloc(bufferlengte*sizeof(char)); struct sockaddr_storage client_addr; socklen_t clilen; struct arg server; int open=1; int useport=input.connection; memset(&client_addr, 0, sizeof(client_addr)); clilen=16; socket2=accept(input.socket1, (struct sockaddr *)&client_addr, &clilen); printf("onze poort: %i\n",useport); server=startClient(2*poort-useport-4,poort_centrale_server,host_centrale_server); if(socket2<0){ printf("problemen bij accept van client, error nummer %i, boodschap: %s\n",socket2, gai_strerror(socket2)); return 0; } while(open){ if(isReadyToRead(server.socket1,3000000)){ error=read(server.socket1,buffer,255); if(error<0)printf("problemen bij het ontvangen van het bericht van de server, nummer %i: %s\n", error, gai_strerror(error)); } else break; error=send(socket2,buffer,strlen(buffer)*sizeof(char),input.hints.ai_flags); if(error<0){ printf("problemen bij verzenden van hetpakket\n"); open=0; } sprintf(buffer,""); if(isReadyToRead(socket2,3000000)){ error=read(socket2,buffer,255); printf("%s\n",buffer); if(error<0){ printf("problemen bij het ontvangen van de client zijn tweede bericht\n"); open=0; } } else break; error=send(server.socket1, buffer, strlen(buffer)*sizeof(char), server.hints.ai_flags); if(error<0){ printf("problemen bij het verzenden van een bericht naar de server"); } } printf("De funcie is gesloten\n"); close(input.socket1); close(socket2); free(buffer); free(tekst); return 0; }
bool NetworkEngine::tryToReconnect() { std::ifstream entrada(SERVER_DATA_FILENAME, std::ifstream::in); std::string server; std::string port; std::string password; std::string listPos; if(!entrada.good()) //No hay fichero o no se puede abrir { return false; } std::getline(entrada, listPos); std::getline(entrada, server, (char)('|'+3)); std::getline(entrada, port); //No se utiliza por ahora std::getline(entrada, password); entrada.close(); if(server.length() == 0) //El fichero esta vacio? { return false; } decode(server); std::cout << "Encontrado server para reconectarse\n"; //std::cout << "Server ip: " << server << std::endl; //std::cout << "Password: " << password << std::endl; bool connnectionAttempSuccess = connectToServer(server, password); if(!connnectionAttempSuccess) //Ha fallado al conectarse { return false; } unsigned int timeout = 1000; bool connectionSuccess = waitUntilConnected(timeout); if(!connectionSuccess) { removeServerFile(); close(); startClient(); } else { aux = atoi(listPos.c_str()); } return connectionSuccess; }
DmsClient::DmsClient(){ this->resize(500,600); data=new QTextBrowser(this); start=new QPushButton("start",this); close=new QPushButton("close",this); data->resize(460,460); data->move(20,20); start->move(150,540); close->move(300,540); /*连接start 和 startClient*/ connect(start,SIGNAL(clicked()), this,SLOT(startClient())); connect(close,SIGNAL(clicked()), this,SLOT(close())); }
void CClientApp::startNode() { if (args().m_enableVnc) { m_vncThread = new CThread(new TMethodJob<CClientApp>( this, &CClientApp::vncThread, NULL)); } // start the client. if this return false then we've failed and // we shouldn't retry. LOG((CLOG_DEBUG1 "starting client")); if (!startClient()) { m_bye(kExitFailed); } }
int main(int argc, char* argv[]){ int mode = 0; if(argc != 2) printUsage(argv[0]); if(!strncmp(argv[1], "-c", 2)) mode = 'c'; if(!strncmp(argv[1], "-s", 2)) mode = 's'; if(!mode) printUsage(argv[0]); if(mode == 's') startServer(); if(mode == 'c') startClient(); return 1; }
/*-------------------------------------------------------------------------------------------------------------------- -- FUNCTION: main -- -- DATE: 2014/09/06 -- -- REVISIONS: (Date and Description) -- -- DESIGNER: Luke Tao, Ian Lee -- -- PROGRAMMER: Luke Tao, Ian Lee -- -- INTERFACE: int main(int argc, char **argv) -- -- RETURNS: 0 for ok, 1 for error -- -- NOTES: main driver function for client program ----------------------------------------------------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* Check to see if user is root */ if (geteuid() != USER_ROOT) { printf("\nYou need to be root to run this.\n\n"); exit(0); } client.dst_port = DEFAULT_PORT; if(parse_options(argc, argv) < 0) exit(1); startClient(); return 0; }
/*! Gets called when a client disconnects from server. */ void WlanConnection::onClientDisconnected(int remainingClients) { qDebug() << "WlanConnection::onClientDisconnected(): Remaining:" << remainingClients; //If we are DontCare and we have no more clients, we'll start discovery and client again if (mConnectAs == DontCare && remainingClients <= 0) { startDiscoveryMgr(); startClient(); mDiscoveryMgr->startDiscovery(mBroadcastPort); } if (mServer && remainingClients > 0) { mConnectedTo = mServer->clientName(remainingClients - 1); } else { mConnectedTo = ""; } setStatus(Connecting); }
void RfCommClient::error(QBluetoothSocket::SocketError err) { qDebug() << __PRETTY_FUNCTION__ << "Got socket error" << err; // remote side has closed the socket, effectively disconnecting it if (state == pendingConnections) { state = dataTransfer; emit disconnected(); stopClient(); // now reconnect and send text string MyThread mythread; mythread.sleep(5); startClient(serviceInfo); connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendText())); lagTimer.start(); } else { qDebug() << __PRETTY_FUNCTION__ << "emitting done"; emit done(); } }
void *contactMasterSlave(char* myAddress){ //Hier gaan we ons aanmelden bij de centrale server //struct sockaddr_storage client_addr; //socklen_t clilen; int error; char* buffer=malloc(bufferlengte*sizeof(char)); gethostname(buffer, 256); //printf("we zitten in de verkeerde functie %s\n",buffer); sprintf(buffer,"%s%i",prefix,1); struct arg input=startClient(poort-3, poort-2,buffer); //printf("we zitten in de verkeerde functie %s\n",myAddress); //printf("we zitten in de verkeerde functie %s\n",getMyIP()); sprintf(buffer,"[{\"add_laadpaal\" : \"%s\"}]\n",myAddress); error=send(input.socket1,buffer,strlen(buffer)*sizeof(char),input.hints.ai_flags); if(error<0){ printf("problemen bij verzenden van het pakket\n"); } error=read(input.socket1,buffer,255); if(error<0) printf("problemen bij het ontvangen van het bericht van de server, nummer %i: %s\n", error, gai_strerror(error)); }
/*------------------------------------------------------------------------------------------------------------------ -- FUNCTION: main -- -- DATE: March 10, 2014 -- -- REVISIONS: -- -- DESIGNER: Robin Hsieh -- -- PROGRAMMER: Robin Hsieh -- -- INTERFACE: int main (int argc , char *argv[]) -- int argc: The number of the arguments put in from the command line. -- char *argv[]: The array of char* of the arguments -- -- RETURNS: int -- Returns an int when program terminates. -- -- NOTES: -- This function is to start the server program to be able to allow clients to connect, and act as a echo server -- that will send message from 1 client, to the rest of other clients connected. This program can also star the -- client program that will be able to connect to a server, and send messages to that server. -- ------------------------------------------------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { char username[128]; char ip[128]; int port; if(argc == 3) { if(strcmp(argv[1], "server") == 0) { port = atoi(argv[2]); startServer(port); } else { exit_message(); } } else if(argc == 5) { if(strcmp(argv[1], "client") == 0) { strcpy(username, argv[2]); strcpy(ip, argv[3]); port = atoi(argv[4]); startClient(username, ip, port); } else { exit_message(); } } else { exit_message(); } return 0; }
int main(int argc, char const *argv[]) { int sockFd, port, n; struct sockaddr_in servAddr; struct hostent *server; if(argc < 3) { fprintf(stderr, "Not the right number of parameters required after %s.\n", argv[0]); exit(0); } port = atoi(argv[2]); // opening the socket if((sockFd = socket(AF_INET, SOCK_STREAM, 0)) < 0) printError('o'); fd.fd = 0; fd.events = POLLIN | POLLRDNORM; // a random number to simulate timeout srand(time(NULL)); rndm = rand()%10; if((server = gethostbyname(argv[1])) < 0) printError('h'); // setting the socket address structure bzero(&servAddr, sizeof(servAddr)); servAddr.sin_family = AF_INET; bcopy(server->h_addr, &servAddr.sin_addr.s_addr, server->h_length); servAddr.sin_port = htons(port); // connecting to the server if(connect(sockFd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) printError('c'); startClient(sockFd); close(sockFd); return 0; }