创客百科

姿势共享,有节操无门槛参与的创客百科,创客动力之源 \ (^_^) /

用户工具

站点工具


en:arduino:libraries:clientconnected

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

en:arduino:libraries:clientconnected [2016/12/25 22:15] (当前版本)
行 1: 行 1:
 +[[en:​arduino:​libraries:​ethernet|Ethernet]] : Client class
 +====== connected() ======
  
 +
 +===== Description =====
 +
 +Whether or not the client is connected. Note that a client is considered connected if the connection has been closed but there is still unread data.
 +===== Syntax =====
 +
 +client.connected()
 +===== Parameters =====
 +
 +none
 +===== Returns =====
 +
 +Returns true if the client is connected, false if not.
 +===== Example =====
 +<code cpp>
 +#include <​Ethernet.h>​
 +#include <​SPI.h>​
 +
 +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 +byte ip[] = { 10, 0, 0, 177 };
 +byte server[] = { 64, 233, 187, 99 }; // Google
 +
 +EthernetClient client;
 +
 +void setup()
 +{
 +  Ethernet.begin(mac,​ ip);
 +  Serial.begin(9600);​
 +
 +  delay(1000);​
 +
 +  Serial.println("​connecting..."​);​
 +
 +  if (client.connect(server,​ 80)) {
 +    Serial.println("​connected"​);​
 +    client.println("​GET /​search?​q=arduino HTTP/​1.0"​);​
 +    client.println();​
 +  } else {
 +    Serial.println("​connection failed"​);​
 +  }
 +}
 +
 +void loop()
 +{
 +  if (client.available()) {
 +    char c = client.read();​
 +    Serial.print(c);​
 +  }
 +
 +  if (!client.connected()) {
 +    Serial.println();​
 +    Serial.println("​disconnecting."​);​
 +    client.stop();​
 +    for(;;)
 +      ;
 +  }
 +}
 +</​code>​
 +
 +
 +[[en:​arduino:​libraries|Reference Home]]
en/arduino/libraries/clientconnected.txt · 最后更改: 2016/12/25 22:15 (外部编辑)