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


C++ EthernetClient::connected方法代码示例

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


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

示例1: loop

void loop() {
  unsigned long time = millis();
  if (next < time) {
    Ethernet.maintain();
    next += send_delay;
    if (next <= time)
      next = time + 1;
    Serial.println("request time !");
    if (client.connected()) {
      Serial.println("already connected");
    } else {
      Serial.print("connecting results : ");
      Serial.println(client.connect("tarzan.info.emn.fr", 80));
    }
    int sent = client.println("GET /ping.php HTTP/1.1");
    sent = client.println(F("Host: tarzan.info.emn.fr"));
    client.println();
  }
  if (client.connected() && client.available() > 0) {
    Serial.println("client received data  : ");
    unsigned char buffer[buff_size + 1];
    while (client.available() > 0) {
      int read = client.read(buffer, buff_size);
      buffer[read] = '\0';
      Serial.println(read);
    }
  }
  if (radio.receiveDone()) {
  }
}
开发者ID:glelouet,项目名称:Connected_House,代码行数:30,代码来源:TcpClient.cpp

示例2: loop

void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}
开发者ID:KISSMonX,项目名称:gr_ethernet_examples,代码行数:26,代码来源:gr_WebClientRepeating.cpp

示例3: readServerResponse

boolean readServerResponse() {
	response = "";
	char inBuf[RESPONSE_BUFFER];

	//response.reserve(RESPONSE_BUFFER);
	int bytesRead = 0;
	if (client.connected()) {
		delay(SERVER_WAIT_TIME);
		Serial.println("awaiting response");
		while (client.available()) {
			char c = client.read();
			Serial.print(c);
			if (bytesRead < RESPONSE_BUFFER) inBuf[bytesRead] = c;
			//else client.flush();
			bytesRead++;
		}
		if (bytesRead > 0) {
			response = inBuf;
			Serial.println("Response Received");
			//if (!client.connected()) client.stop();
			return true;
		}
	}
	return false;
}
开发者ID:mikelduke,项目名称:DMS-RFID-Interlock,代码行数:25,代码来源:PowerInterlock.cpp

示例4: loop

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();

  // we get a request
  if (client) {
    Serial.println(F("Client connected"));
    // an http request ends with a blank line
    boolean done = false;
    while (client.connected() && !done) {
      while (client.available () > 0 && !done) {
        done = processIncomingByte (client.read ());
      }
    }  // end of while client connected

    // get ROV status values as json string
    String rovStatus = getRovStatus();

    // send a standard http response header
    client.println(F("HTTP/1.1 200 OK"));
    client.println(F("Content-Type: text/json"));
    client.println(F("Connection: close"));  // close after completion of the response
    client.println();   // end of HTTP header
    client.println(rovStatus);

    // give the web browser time to receive the data
    delay(10);
    // close the connection:
    client.stop();
    Serial.println(F("Client disconnected"));
  }  // end of got a new client
}  // end of loop
开发者ID:koppii,项目名称:NimanRov,代码行数:32,代码来源:main.cpp

示例5: if

static void 
extract_status_code(struct HTTPObject *h, EthernetClient client){
    unsigned int k,multiplier,j;
    j=0;
    char c;
    const byte STATUS_CODE_START_INDEX = 9;
    const byte STATUS_CODE_END_INDEX = 11;

    while(j<=STATUS_CODE_END_INDEX && client.connected()){
        if(client.available()){
            // We want to extract the 200 from "HTTP/1.1 200 OK". The 
            // status code starts at index 9 in the string and ends at 11
            c = client.read();
            if(j<STATUS_CODE_START_INDEX){
                j++;
            }
            else if(j>=STATUS_CODE_START_INDEX && j<=STATUS_CODE_END_INDEX){
                // code = 10^2 * str[9] + 10^1 * str[10] + 10^0 * str[11]
                // Do ghetto exponentiation here.
                multiplier = 1;
                for(k = 1; k <= 2 - (j - STATUS_CODE_START_INDEX); k++){
                    multiplier *= 10;
                }
                // c - '0' => char to int
                h->statusCode += (c - '0') * multiplier;
                j++;
            }
        }
    }
}
开发者ID:joequery,项目名称:ArduinoRequests,代码行数:30,代码来源:Requests.cpp

示例6: loop

void loop() {
  client = server.available();
  if (client) {                
    while (client.connected()) {
      if (client.available()) {
        if (client.find("GET /")) {
          
          //INICIAR CRONOMETRAGEM
          if (client.find("setCron=")) {
            int charReaded = client.read();
			if(charReaded == 49){
              iniciarCronometragem();
            }
          }
		  
		   //RETORNA O TEMPO DESDE O INICIO		  
          if (client.find("getCron=")) {
            int charReaded = client.read();
			if(charReaded == 49){
              getCronometragem();
			}
          }
        }
      }
      Serial.println();
      break;
    }
    client.println(" HTTP/1.1 200 OK ");
  }
  // give the web browser time to receive the data
  delay(1);
  client.stop();
}
开发者ID:SoftsquareBr,项目名称:telemetria,代码行数:33,代码来源:ArduinoCode2.cpp

示例7: createPoint

void Nimbits::createPoint(String pointName)
{
  EthernetClient client;
  if (client.connect(GOOGLE, PORT))
  {
    client.println(F("POST /service/point HTTP/1.1"));
    String content;
    //  writeAuthParams(content);
    content += "email=";
    content += _ownerEmail;
    if (_accessKey.length() > 0)
    {
      content += ("&key=");
      content += (_accessKey);
    }
    content += "&action=create&point=";
    content += (pointName);
    client.println(F("Host:nimbits1.appspot.com"));
    client.println(F("Connection:close"));
    client.println(F("Cache-Control:max-age=0"));
    client.print(F("Content-Type: application/x-www-form-urlencoded\n"));
    client.print(F("Content-Length: "));
    client.print(content.length());
    client.print(F("\n\n"));
    client.print(content);
    while (client.connected() && !client.available())
    {
      delay(1); //waits for data
    }
    client.stop();
    client.flush();
  }

}
开发者ID:pelrun,项目名称:Logger,代码行数:34,代码来源:Nimbits.cpp

示例8: loop

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) 
  {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        Serial.write(c);

        //*******************233333333333333333333333333333333333333333333*******
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) 
        {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: textml");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("<ml>");
          break;
        }
        if (c == '\n')
        {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}
开发者ID:Zhuanghq7,项目名称:Socket,代码行数:60,代码来源:1.cpp

示例9: loop

//---------------------------------------------------------------------
void loop()
{
    waitForIncomingConnection();
    
    while ( client_.connected() )
    {
        uint8_t cmd = 255;
        
        if ( checkTcpTimeout() )
        {
#ifdef DEBUG_SERIAL
            Serial.println( "ERROR: connection timeout!" );
#endif
            break;
        }
        
        cmd = getCommand();
        if ( cmd == COMMAND_INVALID_COMMAND )
        {
#ifdef DEBUG_SERIAL
            Serial.print( "ERROR: invalid command received: ");
            Serial.println( cmd );
#endif
            break;
        }
        
        processCommand( cmd );
    }
    terminateConnection();
}
开发者ID:BerndBaumann,项目名称:Arduino,代码行数:31,代码来源:main.cpp

示例10: getData

void getData(char *dst)
{
  Serial.println("Trying to grab data from server:");
  
  // from the server, read them and print them:
  int i = 0;
  
  while (!client.available());

  while (client.available()) {
    char c = client.read();
    Serial.print(c);
    
    if (i < 10)
    {
      dst[i] = c;
      //dst[i+1] = 0;
    }

    i++;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}
开发者ID:torkildr,项目名称:display,代码行数:32,代码来源:ehternet_utility.cpp

示例11: GAE

String GAE(String link) {
	httpRequest(link);
	delay(10000);

	String readString = ""; //Reset string

	while (client.available() > 0) {

		char s = client.read();
		//Serial.print(s);			//Complete response w/ headers. For dev mode.
		if (s== '\n') {
			char c = client.read();
			//Serial.print(c);			//Parsed response. For dev mode.
			if (c == '\r') {
				while (client.connected()) {
					char z = client.read();
					readString += z;
				}
			}
		}
	}
	client.stop();
	return(readString);

}
开发者ID:niskyponics,项目名称:niskyponics-arduino,代码行数:25,代码来源:txt_messaging.c

示例12: loopServer

void loopServer() {
	EthernetClient client = server.available();
	if (client) {
		while (client.connected()) {
			if (client.available()) {
				char c = client.read();

				//read char by char HTTP request
				if (readString.length() < 100) {

					//store characters to string
					readString += c;
					//Serial.print(c);
				}

				//if HTTP request has ended
				if (c == '\n') {

					///////////////
					Serial.print(readString); //print to serial monitor for debuging

					//now output HTML data header
					client.println(F("HTTP/1.1 200 OK")); //send new page on browser request
					client.println(F("Content-Type: text/html"));
					client.println();

					client.println(F("Ok"));

					delay(1);
					//stopping client
					client.stop();

					if (readString.indexOf("R1=1") > 0){
						soldoRelays[0]->On();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R1=1");
					}
					if (readString.indexOf("R2=1") > 0){
						soldoRelays[1]->On();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R2=1");
					}
					if (readString.indexOf("R1=0") > 0){
						soldoRelays[0]->Off();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R1=0");
					}
					if (readString.indexOf("R2=0") > 0){
						soldoRelays[1]->Off();
//						Serial.println(">>>>>>>>>>>>");
//						Serial.println("R2=0");
					}
					readString="";

				}
			}
		}
	}
}
开发者ID:dcupovic,项目名称:arduino,代码行数:59,代码来源:SoldoEthernet.cpp

示例13: ProcessClientMessage

void ProcessClientMessage(){   
    // listen for incoming clients
    EthernetClient client = GetAvailableClient();

    if (client) 
    {  
        // an http request ends with a blank line
        boolean currentLineIsBlank = true;

        while (client.connected()) 
        {
            if (client.available()) 
            {
                char c = client.read();

                // if you've gotten to the end of the line (received a newline
                // character) and the line is blank, the http request has ended,
                // so you can send a reply
                if (c == '\n' && currentLineIsBlank) 
                {
                    //Magnetic;Noise;Temperature;Vibration;Voltage

                    String data = "";

                    data += String(GetMagnetic());
                    data += ";";

                    data += String(GetTemperature());
                    data += ";";

                    data += String(GetVibration());
                    data += ";";

                    data += String(GetVoltage());

                    client.println(data);
                    break;
                }

                if (c == '\n') {
                    // you're starting a new line
                    currentLineIsBlank = true;
                }
                else if (c != '\r') 
                {
                    // you've gotten a character on the current line
                    currentLineIsBlank = false;
                }
            }
        }

        // give the web browser time to receive the data
        delay(10);  

        // close the connection:
        client.stop();
    }
}
开发者ID:nikkw,项目名称:Monitoramento-de-containers,代码行数:58,代码来源:Client.cpp

示例14: listenServer

void LeweiTcpClient::listenServer()
{
  EthernetClient clientWeb = server.available();
  if (clientWeb) {
    //Serial.println("new clientWeb");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    String clientStr = "";
    while (clientWeb.connected()) {
      if (clientWeb.available()) {
        char c = clientWeb.read();
        clientStr += c;
        //Serial.write(c);
        
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          clientWeb.println("<html><body><form method='get'>");
          clientWeb.print("KEY<input type='text' name='a' value='");
          clientWeb.print(_userKey);
          clientWeb.print("'>GW<input type='text' name='g' value='");
          clientWeb.print(_gatewayNo);
          clientWeb.println("'><input type='submit'>");
          clientWeb.println("</form></body></html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          if(clientStr.indexOf(" /?a=")>0)
          {
          	Serial.print(clientStr);
          	String userInfoStr = clientStr.substring(clientStr.indexOf(" /?a=")+5,clientStr.indexOf("&g="));
          	userInfoStr += clientStr.substring(clientStr.indexOf("&g=")+3,clientStr.indexOf(" HTTP/1.1"));
            if(userInfoStr.length()>33)writeRom(userInfoStr);
            Serial.println(userInfoStr);
          }
          //Serial.println(clientStr);
          clientStr = "";
          //checkFreeMem();
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    clientWeb.stop();
    clientWeb= NULL;
    //Serial.println("clientWeb disonnected");
  }
  
}
开发者ID:Red680812,项目名称:LeweiTcpClient,代码行数:57,代码来源:LeweiTcpClient.cpp

示例15: updateFeed

void CosmClient::updateFeed(uint32_t feedId, char datastreamId[], double dataToSend) {
    if (_client.available()) {
        char c = _client.read();
        Serial.print(c);
    }

    if (!_client.connected() && lastConnected) {
        Serial.println("disconnecting.\n");
        _client.stop();
    }

    if (!_client.connected() && (millis() - _lastConnMillis > _interval)) {
        sendData(feedId, datastreamId, dataToSend);
        _lastConnMillis = millis();
    }

    lastConnected = _client.connected();
}
开发者ID:Gerst20051,项目名称:ArduinoExamples,代码行数:18,代码来源:Cosm.cpp


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