当前位置: 首页>>代码示例>>C++>>正文


C++ TCPClient::stop方法代码示例

本文整理汇总了C++中TCPClient::stop方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPClient::stop方法的具体用法?C++ TCPClient::stop怎么用?C++ TCPClient::stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPClient的用法示例。


在下文中一共展示了TCPClient::stop方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: response

void response(char* url) {

    // default page is the error page
    const char* page = error;

    // Get the length of our URL and remove the null termination
    int urlLen = strlen(url) - 1;

    // HOME: check only for the length of the URL, since the home page
    // is represented by a forward slash /
    if(urlLen == 1) {

        page = home;

    }

    // MORE: look for the word
    if(memcmp(url, "/more", 5) == 0) {

        page = more;

    }

    // HOME: look for the word
    if(memcmp(url, "/author", 6) == 0) {

        page = author;

    }

    // Inform the browser that everything is ok
    clientWww.write("HTTP/1.1 200 OK\n\r");

    // Tell the encoding that we are using
    clientWww.write("Content-Type: text/html; charset=ascii\n\r");

    // Separate the header from the body with one empty line
    clientWww.write("\n\r");

    // Send our content
    clientWww.write(page);

    // Close the connection
    clientWww.stop();

}
开发者ID:TheraPDX,项目名称:IoT-Raw-Sockets-Examples,代码行数:46,代码来源:tcpDynamicPage.cpp

示例2: loop

void loop () {
    if (!initialised && !connected && (lastCheck + 5000 < millis())) {
        if (WiFi.ready()) {
            connect("www.apple.com", 80);
            if (connected) {
                client.println("GET /library/test/success.html HTTP/1.1");
                client.println("Host: www.apple.com");
                client.println();
                const char *success = "Success";
                unsigned int successLocation = 0;
                while (true) {
                    if (client.available()) {
                        int chr = client.read();
                        if (success[successLocation] == chr) {
                            successLocation ++;
                            if (successLocation == strlen(success)) {
                                initialised = true;
                                Spark.connect();
                                Spark.function("digitalread", tinkerDigitalRead);
                                Spark.function("digitalwrite", tinkerDigitalWrite);
                                Spark.function("analogread", tinkerAnalogRead);
                                Spark.function("analogwrite", tinkerAnalogWrite);
                                client.stop();
                                break;
                            }
                        }
                        else {
                            successLocation = 0;
                        }
                    }
                    else {
                        delay(2);
                    }
                }
            }
        }
        else {
            return;
        }
    }

    if (Serial.available()) {
        if (connected) {
            int bytes = Serial.available();
            for (int i=0; i<bytes; i++) {
                client.write(readSerial());
            }
        }
        else {
            int cmd = readSerial();
            switch (cmd) {
                case 'i':
                    Serial.println("Ready");
                    break;
                case 'c': {
                    char* host;
                    char* stringPort;
                    readWord(); // junk space
                    host = readWord();
                    stringPort = readWord();
                    connect(host, atol(stringPort));
                    free(host);
                    free(stringPort);
                    break;
                }
                case 'w': {
                    char* ssid;
                    char* password;
                    readWord();
                    ssid = readWord();
                    password = readWord();
                    Serial.print("Wifi credentials set to SSID '");
                    Serial.print(ssid);
                    Serial.print("' and password '");
                    Serial.print(password);
                    Serial.println("'");
                    WiFi.setCredentials(ssid, password);
                    break;
                }
                default:
                    Serial.print("Don't know command: ");
                    Serial.write(cmd);
                    Serial.println();
                    break;
            }
        }
    }
    if (connected) {
        int bytes = client.available();
        for (int i=0; i<bytes; i++) {
            Serial.write(client.read());
        }
        
        if (!client.connected()) {
            Serial.println();
            Serial.println("Disconnecting");
            client.stop();
            connected = false;
        }
    }
//.........这里部分代码省略.........
开发者ID:palfrey,项目名称:spark-proxy,代码行数:101,代码来源:application.cpp

示例3: millis

char * http_get(char const * hostname, String path) {

    int i = 0;
    int j = 0;
    int k = 0;
    bool printOnce = false;

    if (client.connect(hostname, 80)) {
        client.print("GET ");
        client.print(path);
        client.println(" HTTP/1.1");
        client.print("HOST: ");
        client.println(hostname);
        client.println("Connection: close");
        client.println();
        client.flush();
    } else {
        if(DEBUG_SERIAL) Serial.println("\r\n\r\nConnection Failed!");
        client.flush();
        client.stop();
        return NULL;
    }

    // wait 5 seconds or less for the host to respond
    uint32_t startTime = millis();
    while(!client.available() && (millis() - startTime) < 5000);

    if(DEBUG_SERIAL) Serial.println("\r\n\r\nREADING HOST DATA......");
    uint32_t lastRead = millis();
    // If the host doesn't close it's connection, we'll timeout in 10 seconds.
    while (client.connected() && (millis() - lastRead) < 10000) {
        while (client.available()) {
            char c = client.read();
            /*
            if(DEBUG_SERIAL) {
              Serial.print(c);
              if(i++ > 100) {
                delay(5);
                i = 0;
              }
            }
            */
            if(c == -1) {
                Serial.print("\r\n\r\nERROR......\r\n\r\n");
                client.flush();
                client.stop();
            }
            if(j++ >= SKIP_CHARS) { // don't buffer the first X bytes to save memory
                if(DEBUG_SERIAL && !printOnce) {
                    Serial.print("\r\n\r\nSAVING......\r\n\r\n");
                    printOnce = true;
                }
                buffer[k++] = c; // save character to buffer
                Serial.print(c);
                delayMicroseconds(100);
                if(k >= BUFFER_SIZE_MAX) { // if we reach the end of our buffer, just bail.
                    Serial.print("\r\n\r\nOUT OF BUFFER SPACE......\r\n\r\n");
                    client.flush();
                    client.stop();
                }
            }
            // as long as we're reading data, reset the lastRead time.
            lastRead = millis();
        } // END while(client.available())
    } // END while(client.connected())

    client.flush();
    client.stop();

    if(DEBUG_SERIAL) {
        Serial.print("\r\nCHARACTERS RECEIVED: ");
        Serial.println(SKIP_CHARS + k);
    }

    return buffer;
}
开发者ID:hiramvillarreal,项目名称:SparkCore-FacebookLikesAlert,代码行数:76,代码来源:application.cpp

示例4: loop

void loop()
{
    int debug = digitalRead(debug_tx);
    
    if(!digitalRead(waitpin_C)){
        // Skip mode, to ensure bootloader stays available
        char buffer[32];
        sprintf(buffer,"skip state: %d\r\n",state);
        Serial1.print(buffer);
        digitalWrite(led, HIGH);   // Turn ON the LED       
        delay(100);
        return;
    }else{
        digitalWrite(led, LOW);   // Turn OFF the LED  
    }

    delay(1);
    switch(state){
        case 0:
            // Waiting for next time
            wait-=10;
            if(wait<0){
                wait = 0;
                state = 1;
            }
            break;
        case 1:
            // Connecting
            if(debug) Serial1.println("connecting");
            if (client.connect(server, 80)){
                if(debug) Serial1.println("connected");
                state = 2;
            }else{
                if(debug) Serial1.println("connection failed state 1");
                wait = RETRY_INTERVAL;
                state = 0;
            }
            break;
        case 2:
            // Requesting
            tries = 0;
            store = 0;
            hash = 0;
            command_i = 0;
            for(int i=0; i<COMMAND_SIZE; i++) command[i] = 0;
            if(client.connected()){
                if(debug) client.println("GET // HTTP/1.0\r\n\r\n");
                wait = RESPONSE_INTERVAL;
                state = 3;
            }else{
                if(debug) Serial1.println("connection lost state 2");
                wait = RETRY_INTERVAL;
                state = 0;
            }
            break;
        case 3:
            // Receiving
            if(client.connected()){
                if (client.available() > 0) 
                {
                    // Print response to serial
                    char c = client.read();
                    if(debug) Serial1.print(c);
                    
                    // If last expected char found, quit reading
                    if(c =='>') hash = 1;
                    // If first char of data found, start storing the string
                    if(c =='<') store = 1;
                    if(store){
                        command[command_i++] = c;
                    }
                }else{
                    if(debug) Serial1.println("nd s3 ");  
                    delay(100);
                }
                // Quit reading
                if(hash){
                    Serial1.println();
                    state = 4;
                }
            }else{
                // We lost connection
                if(debug) Serial1.println("connection lost state 3");
                wait = RETRY_INTERVAL;
                state = 0;
            }
            break;
        case 4:
            // Disconnecting
            if(client.connected()){
                client.stop();
                if(debug) Serial1.println("connection closed state 4");
                wait = RENEW_INTERVAL;
                state = 5;
            }else{
                if(debug) Serial1.println("connection closed by server state 4");
                wait = RENEW_INTERVAL;
                state = 5; 
            }
            break;
//.........这里部分代码省略.........
开发者ID:Jeroen6,项目名称:SparkCore_ThermoWeer,代码行数:101,代码来源:main.cpp

示例5: tcpDisconnect

int tcpDisconnect(String param) {
    tcp.flush();
    tcp.stop();
    return 1;
}
开发者ID:crstffr,项目名称:crstffr-spark-logger,代码行数:5,代码来源:firmware.cpp

示例6: loop

// Called in a loop forever
void loop()
{
	// When you push the button
	if (digitalRead(D0) == HIGH)
	{
		// It might take a couple of loop() iterations to
		// successfully connect to iamresponding.com
		connecting = true;

		// This is how to control the Spark's RGB LED
		RGB.control(true);

		// Red to indicate we're attempting to connect
		RGB.color(255, 0, 0);

		// Push the button once to respond to station.
		// Push it again to cancel.
		if (responding)
		{
			// Do just what the iamresponding.com app does
			data = "{\"keyEntryDesc\":\"CANCELLED\",\"memberIDS\":\"\",\"subscriberID\":\"\",\"userfullname\":\"Jack Bates\"}";
		}
		else
		{
			data = "{\"keyEntryDesc\":\"Station\",\"memberIDS\":\"\",\"subscriberID\":\"\",\"userfullname\":\"Jack Bates\"}";
		}
	}

	// We haven't successfully connected since the button was last
	// pushed, keep trying!
	if (connecting && client.connect(server, 80)) // HTTP is port
	{					      // number 80, FYI
		// We successfully connected, stop trying
		connecting = false;

		// Yellow to indicate we successfully connected and
		// sent the magic words
		RGB.color(255, 255, 0);

		// Again, just ape the iamresponding.com app
		client.println("POST /v3/keyEntries.asmx/AddCallEntry HTTP/1.0");

		client.print("Content-Length: ");
		client.println(strlen(data));

		client.println("Content-Type: application/json");
		client.println("Host: iamresponding.com");
		client.println();

		// Send the magic words
		client.print(data);
	}

	// iamresponding.com sent something back to *us*.
	// (This is our only indication that TCPClient is done
	// transmitting the magic words.  You're welcome to get clever
	// and check if iamresponding.com sent back confirmation or is
	// reporting an error, this just assumes it's confirmation.)
	if (client.available())
	{
		// If we were already responding, then now we aren't
		// (cancelled) and vice versa (if we weren't, then now
		// we are).
		responding = !responding;
		if (responding)
		{
			// Blue to indicate that iamresponding.com
			// knows we're responding to station!
			RGB.color(0, 0, 255);
		}
		else
		{
			// Restore the default RGB LED behavior when
			// we're not responding (cancelled).
			// (By default it shows the Wi-Fi status.)
			RGB.control(false);
		}

		// Tricky: Clean up after transmitting the magic
		// words.  Close the connection to iamresponding.com
		// and discard (flush) anything sent back to us, or
		// else in the next loop() iteration we'll think
		// iamresponding.com sent back something *again*.
		client.stop();
		client.flush();
	}
}
开发者ID:jablko,项目名称:pagetime,代码行数:88,代码来源:application.cpp

示例7: out

void out(const char *s) {server.write( (const uint8_t*)s, strlen(s) );  client.stop();}
开发者ID:garthoff,项目名称:photon-simple-tcpclientserver,代码行数:1,代码来源:tcpserverSimple.cpp


注:本文中的TCPClient::stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。