EthernetClient::setConnectionTimeout()

名称

EthernetClient::setConnectionTimeout()

説明

EthernetClient::connect()とEthernetClient::stop()のタイムアウトを設定する。初期値は1000msである。通信の状態が悪いときに、反応を早くするためには、小さい値を設定する。

書式

void EthernetClient::setConnectionTimeout(uint16_t timeout);

引数

timeoutEthernetClient::connect()とEthernetClient::stop()のタイムアウト値(ミリ秒単位)。

戻り値

なし。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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()
  }
}

オリジナルのページ

https://www.arduino.cc/reference/en/libraries/ethernet/client.setconnectiontimeout/

最終更新日

January 7, 2024

inserted by FC2 system