當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino Ethernet - client.setConnectionTimeout()用法及代碼示例

說明

為 client.connect() 和 client.stop() 設置超時。初始值為 1000 毫秒。您可能更喜歡設置較低的超時值,以使您的程序在出現問題時更具響應性。

用法

client.setConnectionTimeout(milliseconds)

參數

  • 毫秒:client.connect()和client.stop()(uint16_t)的超時時間

返回

示例

#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 0, 0, 177);

// telnet defaults to port 23
EthernetServer server = EthernetServer(23);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // initialize the Ethernet device
  Ethernet.begin(mac, ip);

  // start listening for clients
  server.begin();
}

void loop() {
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client) {
    client.setConnectionTimeout(100);  // set the timeout duration for client.connect() and client.stop()
  }
}

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 Ethernet - client.setConnectionTimeout()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。