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


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

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


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

示例1: tcpKeepAlive

void tcpKeepAlive() {
    unsigned long now = millis();
    if (tcp.connected()) {
        if (now > kaTimer) {
            tcp.flush();
            tcpLog("ENQ"); // For logger view 
            tcp.print(ENQ); // Heartbeat signal
            kaWait = now + 500;
            kaWaiting = true;
            tcpKeepAliveReset();
        }
        if (kaWaiting && (kaWait > now)) {
            if (tcp.available()) {
                char read = tcp.read();
                if (read == ACK) {
                    // tcpLog("ACK");
                    kaWaiting = false;
                }
            }
        } else if (kaWaiting && kaWait < now) {
            tcpLog("Timed out");
            kaWaiting = false;
            tcp.flush();
            tcp.stop();
        }
    }
}
开发者ID:crstffr,项目名称:crstffr-spark-logger,代码行数:27,代码来源:firmware.cpp

示例2: tcpLog

int tcpLog(String message) {
    if (tcp.connected()) {
        tcp.print(STX + Spark.deviceID() + ETX + message + EOT);
        delay(250); // try not to flood socket with too many writes
        return 1;
    } else {
        return -1;
    }
}
开发者ID:crstffr,项目名称:crstffr-spark-logger,代码行数:9,代码来源:firmware.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

// 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


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