void callClient(const char *fileInx){ no_writen = 0; num_blks = 0; num_last_blk = 0; // gets(fileIn); strcpy(fileIn,fileInx); len = strlen(fileIn); printf("\nAttempting Download {%s}\n",fileIn); // DEBUG printf("\nLen = %d\n",len); while(setupConnection()==-1); reportFile(); openfile(); getBlockInfo(); beginread(); readpartial(); // shutdown (sockid,2); // system("sudo cutter 127.0.0.1"); /*FILE TRANSFER ENDS. CLIENT TERMINATES AFTER CLOSING ALL ITS FILES AND SOCKETS*/ fclose(fp); DEBUG printf("client: FILE TRANSFER COMPLETE\n"); close(sockid); return; }
HDTBReturnItem NetworkModule::reach(std::string address, std::string port, std::string message) { std::vector<std::string> req; HDTBReturnItem res(HDTB_RETURN_BAD, ""); // Handle setting up the connection HDTBReturnItem ri = setupConnection(address, port); if(ri.retCode == HDTB_RETURN_GOOD) { req.push_back("send"); req.push_back(message); res = netClient.processRequest(req); // Kill the current connection when complete req.clear(); req.push_back("kill"); netClient.processRequest(req); return res; } else { return errorHandler.generateGenericError("Could not set up connection - [send]"); } return errorHandler.generateGenericError("Uncaught return"); }
void QNetworkAccessHttpBackend::open() { QUrl url = request().url(); bool encrypt = url.scheme() == QLatin1String("https"); setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, encrypt); // set the port number in the reply if it wasn't set url.setPort(url.port(encrypt ? DefaultHttpsPort : DefaultHttpPort)); // check if we have an open connection to this host QByteArray cacheKey = makeCacheKey(this->url()); QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this); if ((http = static_cast<QNetworkAccessHttpBackendCache *>(cache->requestEntryNow(cacheKey))) == 0) { // no entry in cache; create an object http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt); #ifndef QT_NO_NETWORKPROXY QNetworkProxy networkProxy = proxy(); if (encrypt || networkProxy.type() == QNetworkProxy::HttpProxy) http->setTransparentProxy(networkProxy); else http->setCacheProxy(networkProxy); #endif cache->addEntry(cacheKey, http); } setupConnection(); postRequest(); }
int main(int argc, char *argv[]) { int result; //check arguments if(argc != 3 || strlen(argv[1]) != 1 || strlen(argv[2]) != 4){ printf("Please provide 2 arguments %s\n", strerror(EINVAL)); return 1; } //extracting arguments char *type = argv[1]; //port number without /n char. int pp = atoi(argv[2]); char buffer[50]; sprintf(buffer, "%d", pp); strncpy(localInfo.port, buffer, sizeof(localInfo.port)); if(strcmp(type, "s") == 0){ localInfo.isServer = true; }else if(strcmp(type, "c") == 0){ localInfo.isServer = false; }else{ printf("Please type 'c' for client OR 's' for server %s\n", strerror(EINVAL)); return 1; } //prepare the connection if((result = setupConnection()) != 0){ printf("Connection Initiliaziation failed.\n"); return 1; } //listen on socket for incoming connections if(listen(serverSocket, BACKLOG) == -1){ perror("listen"); return -1; } if(localInfo.isServer){ printf("\n********** Server Initialized **********\n"); }else{ printf("\n********** Client Initialized **********\n"); } printf("TIME: %s\n", getTime()); printf("hostname: %s\n", localInfo.hostname); printf("IP: %s port:%s\n",localInfo.ipaddr, localInfo.port); printf("****************************************\n\n"); if(selector() == -1){ printf("SELECT loop error Error\n"); } return 0; }
ExerciseCatalogWindow::ExerciseCatalogWindow(QWidget *parent) : QDialog(parent), ui(new Ui::ExerciseCatalogWindow){ ui->setupUi(this); setWindowTitle(tr("Каталог упражнений")); setupConnection(); setupUI(); }
void main() { while(1) { setupConnection(); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); setupGui(); setupAction(); setupModel(); setupConnection(); }
GuestToolsListener::GuestToolsListener( QString location, QObject *parent ) : QObject(parent) { blockSize = 0; toolSocket = new QLocalSocket(this); //connect(toolSocket, SIGNAL(connected()), this, SLOT(setupConnection())); //server = new QLocalServer(this); toolSocket->connectToServer(location, QIODevice::ReadWrite); qDebug() << "connecting to" << location; setupConnection(); }
PreviewWidget::PreviewWidget(QWidget *parent) : songID(0), collectionButton(COLLECTION_BUTTON_IMAGE, this), songButton(SONG_BUTTON_IMAGE, this), insertSongButton(INSERT_SONG_BUTTON_IMAGE, this), loginInMaskWidget(parent), KTVDialog(parent) { setBackgroundImage(WORD_COUNT_BACKGROUND_IMAGE_PATH); insertSongButton.setPos(QPoint(137, 418)); songButton.setPos(QPoint(246, 409)); collectionButton.setPos(QPoint(305, 418)); setupConnection(); }
int main(int argc, char *argv[]) { MLENV env; MLINK link; int ierr; ierr = PetscInitialize(&argc, &argv, NULL, help);if (ierr) return(ierr); ierr = setupConnection(&env, &link, "192.168.119.1", MATHEMATICA_LINK_CONNECT);CHKERRQ(ierr); ierr = processPackets(link);CHKERRQ(ierr); ierr = cleanupConnection(env, link);CHKERRQ(ierr); ierr = PetscFinalize(); return(ierr); }
void CClient::handleConnected(const CEvent&, void*) { LOG((CLOG_DEBUG1 "connected; wait for hello")); cleanupConnecting(); setupConnection(); // reset clipboard state for (ClipboardID id = 0; id < kClipboardEnd; ++id) { m_ownClipboard[id] = false; m_sentClipboard[id] = false; m_timeClipboard[id] = 0; } }
ControlBar::ControlBar(QWidget *parent,VideoWidget* player) : QWidget(parent) { /* *1.不在任务栏上显示进程图标 *2.保持在父窗口之前 */ setWindowFlags(Qt::Tool |Qt::X11BypassWindowManagerHint|Qt::FramelessWindowHint); //setAttribute(Qt::WA_TranslucentBackground,true); setWindowOpacity(0.7); setFixedHeight(50); timer=new QTimer(this); this->parent=(MainWindow*)parent; this->player=player; setupUI(); setupConnection(); }
int main(int argc, char **argv) { argcheck(argc, argv); // Setup connection char nPORT[7]; // port to connect to char * HOST = new char[DEFAULT_BUFLEN]; // host to connect to SOCKET serverSocket = INVALID_SOCKET; bool success = setupConnection(argc, argv, nPORT, HOST); // if connection setup was successful, continue with socket setup if (success) { //initialize socket SOCKET listenSocket = setupListenSocket(nPORT, argv); if (listenSocket == INVALID_SOCKET) { fprintf(stderr, "error: INVALID_SOCKET, quitting."); //LogF.writetolog("error: INVALID_SOCKET, quitting."); exit(0); } // if the socket setup was successful, continue with testing interface else { // Create server object server = new Client(listenSocket); // testing interface with server try { connectToServerSubsystem(); } catch (ServerException& e) { printf(e.sendEr()); } } } // if connection setup failed, exit else { printf("connection setup failed, exiting"); //LogF.writetolog("connection setup failed."); exit(0); } return 0; // exit }
void callClient(const char *fileInx){ no_writen = 0; num_blks = 0; num_last_blk = 0; // gets(fileIn); strcpy(fileIn,fileInx); len = strlen(fileIn); printf("\nAttempting Download {%s}\n",fileIn); // DEBUG printf("\nLen = %d\n",len); while(setupConnection()==-1); reportFile(); openfile(); getBlockInfo(); beginread(); readpartial(); fclose(fp); close(sockid); return; }
int main(int argc, const char * argv[]) { /* * Actual app */ // Setup Connection to DB setupConnection(); // Create dirs createDirectory(BackgroundDIR); createDirectory(TargetDIR); // Run Menu menuSelect(); // Close Connection closeConnection(); /* * END Actual app */ return 0; }
void CGame::init() { // Load game config config.loadConfig(); // Init the background. background.setSize(sf::Vector2f(SCREEN_WIDTH, SCREEN_HEIGHT)); background.setTexture(ResourceHandler.loadTexture("images/background.png")); // Init the Main Menu gameMenu.addButton(50, 0, ResourceHandler.loadTexture("images/title.gif"), BUT_NOTHING); gameMenu.addButton(283.5, 100, ResourceHandler.loadTexture("images/sub2.gif"), BUT_NOTHING); gameMenu.addButton(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, ResourceHandler.loadTexture("images/test.png"), BUT_PLAY); gameMenu.addButton(SCREEN_WIDTH - 50, SCREEN_HEIGHT - 50, ResourceHandler.loadTexture("images/quit.png"), BUT_QUIT); // Init login menu loginMenu.addButton(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, ResourceHandler.loadTexture("images/login.png"), BUT_LOGIN); loginMenu.addButton(SCREEN_WIDTH / 2 + 100, SCREEN_HEIGHT / 2, ResourceHandler.loadTexture("images/register.png"), BUT_REGISTER); loginMenu.addTextBox(SCREEN_WIDTH / 2 - 75, SCREEN_HEIGHT / 2 - 60, ResourceHandler.loadFont("fonts/TitilliumWeb-Regular.ttf"), 150); loginMenu.addTextBox(SCREEN_WIDTH / 2 - 75, SCREEN_HEIGHT / 2 - 30, ResourceHandler.loadFont("fonts/TitilliumWeb-Regular.ttf"), 150); loginMenu.addButton(SCREEN_WIDTH - 50, SCREEN_HEIGHT - 50, ResourceHandler.loadTexture("images/quit.png"), BUT_QUIT); // Init networking setupConnection(); setState(MENU); }
//------------------------------------ void ofxRemoteCameraClient::threadedFunction(){ string msg; while (isThreadRunning()) { if(connected){ /*********SENDING THE REQUEST*********/ if(changeRequested){ requestedImageType=tmpImageType; compressionQuality=tmpCompressionQuality; requestedWidth=tmpW; requestedHeight=tmpH; changeRequested=false; } msg.clear(); msg=msg+ofToString(requestedWidth, 0)+SIZE_SEPARATOR+ofToString(requestedHeight, 0)+DATA_SEPARATOR; msg=msg+ofToString(compressionQuality,0)+DATA_SEPARATOR; msg=msg+ofToString(requestedImageType, 0)+DATA_SEPARATOR; while (msg.size()<MSG_SIZE) { msg=msg+"0"; } if(verbose) cout << "SENDING REQUEST: "<<msg<<"\n"; if(sendData(client->TCPClient,(unsigned char*)msg.c_str(), MSG_SIZE)>0){ if(verbose)cout << "SIZE:"; char s2[MSG_SIZE]; if(receiveData(client->TCPClient,(unsigned char*)s2,MSG_SIZE)>0){ intSize = ofToInt( string( s2 ) ); if(verbose)cout<< " "<< intSize<<"\n"; lock(); if(verbose)cout <<"START RECEIVING DATA\n"; if(receiveData(client->TCPClient,auxPixels,intSize)>0) { if(compressionQuality<NO_COMPRESSION){ decompress(auxPixels,intSize, requestedWidth, requestedHeight,getPixelSize(requestedImageType)); unsigned char *tmp=(unsigned char*)auxPixels; auxPixels=compressedData; compressedData=tmp; } if(verbose) cout << "DATA RECIEVED AND COMPRESSED\n"; newData=connected; unlock(); continue; } unlock(); } } cout<<"Error!!!\n"; connected=false; } else{ setupConnection(); if(!isConnected()){ cout << "Connection refused. Sleeping...."; #ifdef TARGET_WIN32 Sleep(SLEEPING_TIME); #else sleep(SLEEPING_TIME); #endif cout << "done\n"; } else { cout << "Connected to "<<address<<":"<<port<<"\n"; } } } }
int activeOpen(Connection *conn, const struct sockaddr_in laddr) { Segment syn, synack, acksynack; char ssyn[RUSP_SGMS + 1], ssynack[RUSP_SGMS + 1], sacksynack[RUSP_SGMS + 1]; int asock, synretrans; struct sockaddr_in aaddr; struct timespec start, end; long double sampleRTT; if (getConnectionState(conn) != RUSP_CLOSED) ERREXIT("Cannot synchronize connection: connection not closed."); asock = openSocket(); syn = createSegment(RUSP_SYN, 0, 0, 0, NULL); serializeSegment(syn, ssyn); for (synretrans = 0; synretrans < RUSP_SYN_RETR; synretrans++) { clock_gettime(CLOCK_MONOTONIC, &start); writeUSocket(asock, laddr, ssyn, strlen(ssyn)); DBGFUNC(RUSP_DEBUG, printOutSegment(laddr, syn)); setConnectionState(conn, RUSP_SYNSND); if (!selectSocket(asock, RUSP_SAMPLRTT)) continue; readUSocket(asock, &aaddr, ssynack, RUSP_SGMS); clock_gettime(CLOCK_MONOTONIC, &end); sampleRTT = getElapsed(start, end); deserializeSegment(ssynack, &synack); DBGFUNC(RUSP_DEBUG, printInSegment(aaddr, synack)); if ((synack.hdr.ctrl == (RUSP_SYN | RUSP_SACK)) & (synack.hdr.ackn == RUSP_NXTSEQN(syn.hdr.seqn, 1))) { setConnectionState(conn, RUSP_SYNRCV); acksynack = createSegment(RUSP_SACK, 0, RUSP_NXTSEQN(syn.hdr.seqn, 1), RUSP_NXTSEQN(synack.hdr.seqn, 1), NULL); serializeSegment(acksynack, sacksynack); writeUSocket(asock, aaddr, sacksynack, strlen(sacksynack)); DBGFUNC(RUSP_DEBUG, printOutSegment(aaddr, acksynack)); setupConnection(conn, asock, aaddr, acksynack.hdr.seqn, acksynack.hdr.ackn, sampleRTT); return conn->connid; } } closeSocket(asock); setConnectionState(conn, RUSP_CLOSED); return -1; }
void CGame::gameRegister() { sf::Packet packet; loginPacket info; std::string tmp; short packetType; sf::Clock retry; std::cout << "Sending register..." << std::endl; // Setup connection setupConnection(); // Setup login packet info.packetType = GAMEREGISTER; strcpy(info.username, loginMenu.getTextBoxes().at(0)->toString().c_str()); tmp = loginMenu.getTextBoxes().at(1)->toString() + "coolsalt"; strcpy(info.password, md5(tmp).c_str()); packet << info; // Send login packet to server if (!gameClient.send(packet)) { std::cout << "failed to login" << std::endl; setState(QUIT); } // Wait from response packet.clear(); std::cout << "Waiting for server response..."; retry.restart(); while (gameClient.receive(&packet) == 0) { if (retry.getElapsedTime().asSeconds() > 3) { gameClient.Reset(); return; } } packet >> packetType; switch (packetType) { case LOGIN_REG_SUCCESS: std::cout << "Registered & Logged in!" << std::endl; setState(PLAYING); return; break; case LOGIN_REG_INUSE: std::cout << "User already in use!" << std::endl; setState(LOGIN); return; break; default: std::cout << "Unexpected response: " << packetType << std::endl; setState(LOGIN); gameClient.Reset(); return; break; } setState(LOGIN); }
void CGame::login() { sf::Packet packet; loginPacket info; std::string tmp; short packetType; sf::Clock retry; std::cout << "Sending login..." << std::endl; // Setup login packet info.packetType = GAMELOGIN; strcpy(info.username, loginMenu.getTextBoxes().at(0)->toString().c_str()); tmp = loginMenu.getTextBoxes().at(1)->toString() + "coolsalt"; strcpy(info.password, md5(tmp).c_str()); packet << info; // Init connection setupConnection(); // Send login packet to server if (!gameClient.send(packet)) { std::cout << "failed to login" << std::endl; setState(QUIT); } // Wait from response packet.clear(); std::cout << "Waiting for server response..."; retry.restart(); while (gameClient.receive(&packet) == 0) { if (retry.getElapsedTime().asSeconds() > 3) { std::cout << "timed out" << std::endl; gameClient.Reset(); return; } } packet >> packetType; switch (packetType) { case LOGIN_AUTH_VALID: std::cout << "Logged in!" << std::endl; setState(PLAYING); return; break; case LOGIN_AUTH_UNKNOWN_USER: std::cout << "Invalid user!" << std::endl; setState(LOGIN); return; break; case LOGIN_AUTH_INVALID_PASSWORD: std::cout << "Unknown password!" << std::endl; setState(LOGIN); return; break; default: std::cout << "Unexpected response: " << packetType << std::endl; setState(LOGIN); gameClient.Reset(); return; break; } setState(LOGIN); }
int main(int argc, const char * argv[]) { setupConnection(); return 0; }
JBlockerMessageViewBox::JBlockerMessageViewBox(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f),p_textBrowser(0), p_exitButton(0) { setupUI(); setupConnection(); }
ConnectionId passiveOpen(Connection *lconn) { Connection *aconn = NULL; Segment syn, synack, acksynack; char ssyn[RUSP_SGMS + 1], ssynack[RUSP_SGMS + 1], sacksynack[RUSP_SGMS + 1]; int asock, synackretrans; struct sockaddr_in caddr; struct timespec start, end; long double sampleRTT; while (getConnectionState(lconn) == RUSP_LISTEN) { readUSocket(lconn->sock.fd, &caddr, ssyn, RUSP_SGMS); deserializeSegment(ssyn, &syn); DBGFUNC(RUSP_DEBUG, printInSegment(caddr, syn)); if (syn.hdr.ctrl != RUSP_SYN) continue; setConnectionState(lconn, RUSP_SYNRCV); asock = openSocket(); synack = createSegment(RUSP_SYN | RUSP_SACK, 0, 10, RUSP_NXTSEQN(syn.hdr.seqn, 1), NULL); serializeSegment(synack, ssynack); for (synackretrans = 0; synackretrans < RUSP_RETR; synackretrans++) { clock_gettime(CLOCK_MONOTONIC, &start); writeUSocket(asock, caddr, ssynack, strlen(ssynack)); DBGFUNC(RUSP_DEBUG, printOutSegment(caddr, synack)); setConnectionState(lconn, RUSP_SYNSND); if (!selectSocket(asock, RUSP_SAMPLRTT)) continue; readUSocket(asock, &caddr, sacksynack, RUSP_SGMS); clock_gettime(CLOCK_MONOTONIC, &end); sampleRTT = getElapsed(start, end); deserializeSegment(sacksynack, &acksynack); DBGFUNC(RUSP_DEBUG, printInSegment(caddr, acksynack)); if ((acksynack.hdr.ctrl == RUSP_SACK) & (acksynack.hdr.seqn == synack.hdr.ackn) & (acksynack.hdr.ackn == RUSP_NXTSEQN(synack.hdr.seqn, 1))) { aconn = createConnection(); setConnectionState(aconn, RUSP_SYNSND); setupConnection(aconn, asock, caddr, acksynack.hdr.ackn, acksynack.hdr.seqn, sampleRTT); setConnectionState(lconn, RUSP_LISTEN); return aconn->connid; } } closeSocket(asock); setConnectionState(lconn, RUSP_LISTEN); } return -1; }
void QNetworkAccessHttpBackend::open() { QUrl url = request().url(); bool encrypt = url.scheme().toLower() == QLatin1String("https"); setAttribute(QNetworkRequest::ConnectionEncryptedAttribute, encrypt); // set the port number in the reply if it wasn't set url.setPort(url.port(encrypt ? DefaultHttpsPort : DefaultHttpPort)); QNetworkProxy *theProxy = 0; #ifndef QT_NO_NETWORKPROXY QNetworkProxy transparentProxy, cacheProxy; foreach (const QNetworkProxy &p, proxyList()) { // use the first proxy that works // for non-encrypted connections, any transparent or HTTP proxy // for encrypted, only transparent proxies if (!encrypt && (p.capabilities() & QNetworkProxy::CachingCapability) && (p.type() == QNetworkProxy::HttpProxy || p.type() == QNetworkProxy::HttpCachingProxy)) { cacheProxy = p; transparentProxy = QNetworkProxy::NoProxy; theProxy = &cacheProxy; break; } if (p.isTransparentProxy()) { transparentProxy = p; cacheProxy = QNetworkProxy::NoProxy; theProxy = &transparentProxy; break; } } // check if at least one of the proxies if (transparentProxy.type() == QNetworkProxy::DefaultProxy && cacheProxy.type() == QNetworkProxy::DefaultProxy) { // unsuitable proxies error(QNetworkReply::ProxyNotFoundError, tr("No suitable proxy found")); finished(); return; } #endif // check if we have an open connection to this host cacheKey = makeCacheKey(this, theProxy); QNetworkAccessCache *cache = QNetworkAccessManagerPrivate::getCache(this); if ((http = static_cast<QNetworkAccessHttpBackendCache *>(cache->requestEntryNow(cacheKey))) == 0) { // no entry in cache; create an object http = new QNetworkAccessHttpBackendCache(url.host(), url.port(), encrypt); #ifndef QT_NO_NETWORKPROXY http->setTransparentProxy(transparentProxy); http->setCacheProxy(cacheProxy); #endif cache->addEntry(cacheKey, http); } setupConnection(); postRequest(); }