Arduino  1.8.10
EthernetClient クラス

#include <Ethernet.h>

EthernetClient の継承関係図
Client Stream Print

公開メンバ関数

 EthernetClient ()
 
 EthernetClient (uint8_t s)
 
uint8_t status ()
 
virtual int connect (IPAddress ip, uint16_t port)
 
virtual int connect (const char *host, uint16_t port)
 
virtual int availableForWrite (void)
 
virtual size_t write (uint8_t)
 
virtual size_t write (const uint8_t *buf, size_t size)
 
virtual int available ()
 
virtual int read ()
 
virtual int read (uint8_t *buf, size_t size)
 
virtual int peek ()
 
virtual void flush ()
 
virtual void stop ()
 
virtual uint8_t connected ()
 
virtual operator bool ()
 
virtual bool operator== (const bool value)
 
virtual bool operator!= (const bool value)
 
virtual bool operator== (const EthernetClient &)
 
virtual bool operator!= (const EthernetClient &rhs)
 
uint8_t getSocketNumber () const
 
virtual uint16_t localPort ()
 
virtual IPAddress remoteIP ()
 
virtual uint16_t remotePort ()
 
virtual void setConnectionTimeout (uint16_t timeout)
 
virtual size_t write (uint8_t)=0
 
size_t write (const char *str)
 
virtual size_t write (const uint8_t *buffer, size_t size)
 
size_t write (const char *buffer, size_t size)
 
- 基底クラス Stream に属する継承公開メンバ関数
 Stream ()
 
void setTimeout (unsigned long timeout)
 
unsigned long getTimeout (void)
 
bool find (char *target)
 
bool find (uint8_t *target)
 
bool find (char *target, size_t length)
 
bool find (uint8_t *target, size_t length)
 
bool find (char target)
 
bool findUntil (char *target, char *terminator)
 
bool findUntil (uint8_t *target, char *terminator)
 
bool findUntil (char *target, size_t targetLen, char *terminate, size_t termLen)
 
bool findUntil (uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
 
long parseInt (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
float parseFloat (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
size_t readBytes (char *buffer, size_t length)
 
size_t readBytes (uint8_t *buffer, size_t length)
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
size_t readBytesUntil (char terminator, uint8_t *buffer, size_t length)
 
String readString ()
 
String readStringUntil (char terminator)
 
- 基底クラス Print に属する継承公開メンバ関数
 Print ()
 
int getWriteError ()
 
void clearWriteError ()
 
size_t write (const char *str)
 
size_t write (const char *buffer, size_t size)
 
size_t print (const __FlashStringHelper *)
 
size_t print (const String &)
 
size_t print (const char[])
 
size_t print (char)
 
size_t print (unsigned char, int=DEC)
 
size_t print (int, int=DEC)
 
size_t print (unsigned int, int=DEC)
 
size_t print (long, int=DEC)
 
size_t print (unsigned long, int=DEC)
 
size_t print (double, int=2)
 
size_t print (const Printable &)
 
size_t println (const __FlashStringHelper *)
 
size_t println (const String &s)
 
size_t println (const char[])
 
size_t println (char)
 
size_t println (unsigned char, int=DEC)
 
size_t println (int, int=DEC)
 
size_t println (unsigned int, int=DEC)
 
size_t println (long, int=DEC)
 
size_t println (unsigned long, int=DEC)
 
size_t println (double, int=2)
 
size_t println (const Printable &)
 
size_t println (void)
 

フレンド

class EthernetServer
 

その他の継承メンバ

- 基底クラス Client に属する継承限定公開メンバ関数
uint8_t * rawIPAddress (IPAddress &addr)
 
- 基底クラス Stream に属する継承限定公開メンバ関数
int timedRead ()
 
int timedPeek ()
 
int peekNextDigit (LookaheadMode lookahead, bool detectDecimal)
 
long parseInt (char ignore)
 
float parseFloat (char ignore)
 
int findMulti (struct MultiTarget *targets, int tCount)
 
- 基底クラス Print に属する継承限定公開メンバ関数
void setWriteError (int err=1)
 
- 基底クラス Stream に属する継承限定公開変数類
unsigned long _timeout
 
unsigned long _startMillis
 

詳解

Ethernet.h214 行目に定義があります。

構築子と解体子

◆ EthernetClient() [1/2]

EthernetClient::EthernetClient ( )
inline

Ethernet.h216 行目に定義があります。

216 : sockindex(MAX_SOCK_NUM), _timeout(1000) { }
#define MAX_SOCK_NUM
Definition: Ethernet.h:39

◆ EthernetClient() [2/2]

EthernetClient::EthernetClient ( uint8_t  s)
inline

Ethernet.h217 行目に定義があります。

217 : sockindex(s), _timeout(1000) { }

関数詳解

◆ available()

int EthernetClient::available ( void  )
virtual

Clientを実装しています。

EthernetClient.cpp91 行目に定義があります。

92 {
93  if (sockindex >= MAX_SOCK_NUM) return 0;
94  return Ethernet.socketRecvAvailable(sockindex);
95  // TODO: do the Wiznet chips automatically retransmit TCP ACK
96  // packets if they are lost by the network? Someday this should
97  // be checked by a man-in-the-middle test which discards certain
98  // packets. If ACKs aren't resent, we would need to check for
99  // returning 0 here and after a timeout do another Sock_RECV
100  // command to cause the Wiznet chip to resend the ACK packet.
101 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242

◆ availableForWrite()

int EthernetClient::availableForWrite ( void  )
virtual

Printを再実装しています。

EthernetClient.cpp72 行目に定義があります。

73 {
74  if (sockindex >= MAX_SOCK_NUM) return 0;
75  return Ethernet.socketSendAvailable(sockindex);
76 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242

◆ connect() [1/2]

int EthernetClient::connect ( IPAddress  ip,
uint16_t  port 
)
virtual

Clientを実装しています。

EthernetClient.cpp42 行目に定義があります。

43 {
44  if (sockindex < MAX_SOCK_NUM) {
45  if (Ethernet.socketStatus(sockindex) != SnSR::CLOSED) {
46  Ethernet.socketDisconnect(sockindex); // TODO: should we call stop()?
47  }
48  sockindex = MAX_SOCK_NUM;
49  }
50 #if defined(ESP8266) || defined(ESP32)
51  if (ip == IPAddress((uint32_t)0) || ip == IPAddress(0xFFFFFFFFul)) return 0;
52 #else
53  if (ip == IPAddress(0ul) || ip == IPAddress(0xFFFFFFFFul)) return 0;
54 #endif
55  sockindex = Ethernet.socketBegin(SnMR::TCP, 0);
56  if (sockindex >= MAX_SOCK_NUM) return 0;
57  Ethernet.socketConnect(sockindex, rawIPAddress(ip), port);
58  uint32_t start = millis();
59  while (1) {
60  uint8_t stat = Ethernet.socketStatus(sockindex);
61  if (stat == SnSR::ESTABLISHED) return 1;
62  if (stat == SnSR::CLOSE_WAIT) return 1;
63  if (stat == SnSR::CLOSED) return 0;
64  if (millis() - start > _timeout) break;
65  delay(1);
66  }
67  Ethernet.socketClose(sockindex);
68  sockindex = MAX_SOCK_NUM;
69  return 0;
70 }
unsigned long millis(void)
Definition: wiring.c:65
#define MAX_SOCK_NUM
void delay(unsigned long)
Definition: wiring.c:106
uint8_t * rawIPAddress(IPAddress &addr)
Definition: Client.h:42
EthernetClass Ethernet
Definition: Ethernet.cpp:242
static const uint8_t CLOSE_WAIT
Definition: w5100.h:98
static const uint8_t CLOSED
Definition: w5100.h:89
static const uint8_t ESTABLISHED
Definition: w5100.h:94
static const uint8_t TCP
Definition: w5100.h:57

◆ connect() [2/2]

int EthernetClient::connect ( const char *  host,
uint16_t  port 
)
virtual

Clientを実装しています。

EthernetClient.cpp26 行目に定義があります。

27 {
28  DNSClient dns; // Look up the host first
29  IPAddress remote_addr;
30 
31  if (sockindex < MAX_SOCK_NUM) {
32  if (Ethernet.socketStatus(sockindex) != SnSR::CLOSED) {
33  Ethernet.socketDisconnect(sockindex); // TODO: should we call stop()?
34  }
35  sockindex = MAX_SOCK_NUM;
36  }
37  dns.begin(Ethernet.dnsServerIP());
38  if (!dns.getHostByName(host, remote_addr)) return 0; // TODO: use _timeout
39  return connect(remote_addr, port);
40 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242
virtual int connect(IPAddress ip, uint16_t port)
static IPAddress dnsServerIP()
Definition: Ethernet.h:98
static const uint8_t CLOSED
Definition: w5100.h:89
Definition: Dns.h:10
Definition: Dhcp.h:62

◆ connected()

uint8_t EthernetClient::connected ( )
virtual

Clientを実装しています。

EthernetClient.cpp154 行目に定義があります。

155 {
156  if (sockindex >= MAX_SOCK_NUM) return 0;
157 
158  uint8_t s = Ethernet.socketStatus(sockindex);
159  return !(s == SnSR::LISTEN || s == SnSR::CLOSED || s == SnSR::FIN_WAIT ||
160  (s == SnSR::CLOSE_WAIT && !available()));
161 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242
static const uint8_t CLOSE_WAIT
Definition: w5100.h:98
static const uint8_t LISTEN
Definition: w5100.h:91
virtual int available()
static const uint8_t CLOSED
Definition: w5100.h:89
static const uint8_t FIN_WAIT
Definition: w5100.h:95

◆ flush()

void EthernetClient::flush ( void  )
virtual

Clientを実装しています。

EthernetClient.cpp123 行目に定義があります。

124 {
125  while (sockindex < MAX_SOCK_NUM) {
126  uint8_t stat = Ethernet.socketStatus(sockindex);
127  if (stat != SnSR::ESTABLISHED && stat != SnSR::CLOSE_WAIT) return;
128  if (Ethernet.socketSendAvailable(sockindex) >= W5100.SSIZE) return;
129  }
130 }
static const uint16_t SSIZE
Definition: w5100.h:312
#define MAX_SOCK_NUM
W5100Class W5100
Definition: w5100.cpp:60
EthernetClass Ethernet
Definition: Ethernet.cpp:242
static const uint8_t CLOSE_WAIT
Definition: w5100.h:98
static const uint8_t ESTABLISHED
Definition: w5100.h:94

◆ getSocketNumber()

uint8_t EthernetClient::getSocketNumber ( ) const
inline

Ethernet.h237 行目に定義があります。

237 { return sockindex; }

◆ localPort()

uint16_t EthernetClient::localPort ( )
virtual

EthernetClient.cpp181 行目に定義があります。

182 {
183  if (sockindex >= MAX_SOCK_NUM) return 0;
184  uint16_t port;
186  port = W5100.readSnPORT(sockindex);
188  return port;
189 }
#define MAX_SOCK_NUM
W5100Class W5100
Definition: w5100.cpp:60
static void beginTransaction(SPISettings settings)
Definition: SPI.h:178
#define SPI_ETHERNET_SETTINGS
Definition: w5100.h:21
SPIClass SPI
Definition: SPI.cpp:16
static void endTransaction(void)
Definition: SPI.h:260

◆ operator bool()

virtual EthernetClient::operator bool ( )
inlinevirtual

Clientを実装しています。

Ethernet.h232 行目に定義があります。

232 { return sockindex < MAX_SOCK_NUM; }
#define MAX_SOCK_NUM
Definition: Ethernet.h:39

◆ operator!=() [1/2]

virtual bool EthernetClient::operator!= ( const bool  value)
inlinevirtual

Ethernet.h234 行目に定義があります。

234 { return bool() != value; }
#define bool
Definition: stdbool.h:33

◆ operator!=() [2/2]

virtual bool EthernetClient::operator!= ( const EthernetClient rhs)
inlinevirtual

Ethernet.h236 行目に定義があります。

236 { return !this->operator==(rhs); }
virtual bool operator==(const bool value)
Definition: Ethernet.h:233

◆ operator==() [1/2]

virtual bool EthernetClient::operator== ( const bool  value)
inlinevirtual

Ethernet.h233 行目に定義があります。

233 { return bool() == value; }
#define bool
Definition: stdbool.h:33

◆ operator==() [2/2]

bool EthernetClient::operator== ( const EthernetClient rhs)
virtual

EthernetClient.cpp171 行目に定義があります。

172 {
173  if (sockindex != rhs.sockindex) return false;
174  if (sockindex >= MAX_SOCK_NUM) return false;
175  if (rhs.sockindex >= MAX_SOCK_NUM) return false;
176  return true;
177 }
#define MAX_SOCK_NUM

◆ peek()

int EthernetClient::peek ( void  )
virtual

Clientを実装しています。

EthernetClient.cpp109 行目に定義があります。

110 {
111  if (sockindex >= MAX_SOCK_NUM) return -1;
112  if (!available()) return -1;
113  return Ethernet.socketPeek(sockindex);
114 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242
virtual int available()

◆ read() [1/2]

int EthernetClient::read ( void  )
virtual

Clientを実装しています。

EthernetClient.cpp116 行目に定義があります。

117 {
118  uint8_t b;
119  if (Ethernet.socketRecv(sockindex, &b, 1) > 0) return b;
120  return -1;
121 }
EthernetClass Ethernet
Definition: Ethernet.cpp:242

◆ read() [2/2]

int EthernetClient::read ( uint8_t *  buf,
size_t  size 
)
virtual

Clientを実装しています。

EthernetClient.cpp103 行目に定義があります。

104 {
105  if (sockindex >= MAX_SOCK_NUM) return 0;
106  return Ethernet.socketRecv(sockindex, buf, size);
107 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242

◆ remoteIP()

IPAddress EthernetClient::remoteIP ( )
virtual

EthernetClient.cpp193 行目に定義があります。

194 {
195  if (sockindex >= MAX_SOCK_NUM) return IPAddress((uint32_t)0);
196  uint8_t remoteIParray[4];
198  W5100.readSnDIPR(sockindex, remoteIParray);
200  return IPAddress(remoteIParray);
201 }
#define MAX_SOCK_NUM
W5100Class W5100
Definition: w5100.cpp:60
static void beginTransaction(SPISettings settings)
Definition: SPI.h:178
#define SPI_ETHERNET_SETTINGS
Definition: w5100.h:21
SPIClass SPI
Definition: SPI.cpp:16
static void endTransaction(void)
Definition: SPI.h:260

◆ remotePort()

uint16_t EthernetClient::remotePort ( )
virtual

EthernetClient.cpp205 行目に定義があります。

206 {
207  if (sockindex >= MAX_SOCK_NUM) return 0;
208  uint16_t port;
210  port = W5100.readSnDPORT(sockindex);
212  return port;
213 }
#define MAX_SOCK_NUM
W5100Class W5100
Definition: w5100.cpp:60
static void beginTransaction(SPISettings settings)
Definition: SPI.h:178
#define SPI_ETHERNET_SETTINGS
Definition: w5100.h:21
SPIClass SPI
Definition: SPI.cpp:16
static void endTransaction(void)
Definition: SPI.h:260

◆ setConnectionTimeout()

virtual void EthernetClient::setConnectionTimeout ( uint16_t  timeout)
inlinevirtual

Ethernet.h241 行目に定義があります。

241 { _timeout = timeout; }

◆ status()

uint8_t EthernetClient::status ( )

EthernetClient.cpp163 行目に定義があります。

164 {
165  if (sockindex >= MAX_SOCK_NUM) return SnSR::CLOSED;
166  return Ethernet.socketStatus(sockindex);
167 }
#define MAX_SOCK_NUM
EthernetClass Ethernet
Definition: Ethernet.cpp:242
static const uint8_t CLOSED
Definition: w5100.h:89

◆ stop()

void EthernetClient::stop ( )
virtual

Clientを実装しています。

EthernetClient.cpp132 行目に定義があります。

133 {
134  if (sockindex >= MAX_SOCK_NUM) return;
135 
136  // attempt to close the connection gracefully (send a FIN to other side)
137  Ethernet.socketDisconnect(sockindex);
138  unsigned long start = millis();
139 
140  // wait up to a second for the connection to close
141  do {
142  if (Ethernet.socketStatus(sockindex) == SnSR::CLOSED) {
143  sockindex = MAX_SOCK_NUM;
144  return; // exit the loop
145  }
146  delay(1);
147  } while (millis() - start < _timeout);
148 
149  // if it hasn't closed, close it forcefully
150  Ethernet.socketClose(sockindex);
151  sockindex = MAX_SOCK_NUM;
152 }
unsigned long millis(void)
Definition: wiring.c:65
#define MAX_SOCK_NUM
void delay(unsigned long)
Definition: wiring.c:106
EthernetClass Ethernet
Definition: Ethernet.cpp:242
static const uint8_t CLOSED
Definition: w5100.h:89

◆ write() [1/6]

size_t EthernetClient::write ( uint8_t  b)
virtual

Clientを実装しています。

EthernetClient.cpp78 行目に定義があります。

79 {
80  return write(&b, 1);
81 }
virtual size_t write(uint8_t)

◆ write() [2/6]

size_t EthernetClient::write ( const uint8_t *  buf,
size_t  size 
)
virtual

Clientを実装しています。

EthernetClient.cpp83 行目に定義があります。

84 {
85  if (sockindex >= MAX_SOCK_NUM) return 0;
86  if (Ethernet.socketSend(sockindex, buf, size)) return size;
87  setWriteError();
88  return 0;
89 }
#define MAX_SOCK_NUM
void setWriteError(int err=1)
Definition: Print.h:44
EthernetClass Ethernet
Definition: Ethernet.cpp:242

◆ write() [3/6]

size_t Print::write

Print.cpp34 行目に定義があります。

35 {
36  size_t n = 0;
37  while (size--) {
38  if (write(*buffer++)) n++;
39  else break;
40  }
41  return n;
42 }
char buffer[42]
virtual size_t write(uint8_t)

◆ write() [4/6]

size_t Print::write
inline

Print.h52 行目に定義があります。

52  {
53  if (str == NULL) return 0;
54  return write((const uint8_t *)str, strlen(str));
55  }
const char * str
Definition: console.c:41
size_t strlen(const char *) __ATTR_PURE__
Calculate the length of a string.
virtual size_t write(uint8_t)
#define NULL
Definition: def.h:44

◆ write() [5/6]

size_t Print::write
inline

Print.h57 行目に定義があります。

57  {
58  return write((const uint8_t *)buffer, size);
59  }
char buffer[42]
virtual size_t write(uint8_t)

◆ write() [6/6]

virtual size_t Print::write

フレンドと関連関数の詳解

◆ EthernetServer

friend class EthernetServer
friend

Ethernet.h243 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: