STM32Ethernet
Arduino Ethernet library for STM32 boards
Loading...
Searching...
No Matches
EthernetClient.h
Go to the documentation of this file.
1
8#ifndef ethernetclient_h
9#define ethernetclient_h
10#include "Arduino.h"
11#include "Print.h"
12#include "Client.h"
13#include "IPAddress.h"
14#include "utility/stm32_eth.h"
15
16class EthernetClient : public Client {
17
18 public:
23
31 EthernetClient(uint8_t sock);
32
41 EthernetClient(struct tcp_struct *tcpClient);
42
49 uint8_t status();
60 virtual int connect(IPAddress ip, uint16_t port);
72 virtual int connect(const char *host, uint16_t port);
79 virtual size_t write(uint8_t b);
93 virtual size_t write(const uint8_t *buf, size_t size);
101 virtual int available();
107 virtual int read();
115 virtual int read(uint8_t *buf, size_t size);
123 virtual int peek();
129 virtual void flush();
138 virtual void stop();
147 virtual uint8_t connected();
157 virtual operator bool();
164 virtual bool operator==(const bool value)
165 {
166 return bool() == value;
167 }
174 virtual bool operator!=(const bool value)
175 {
176 return bool() != value;
177 }
188 virtual bool operator==(const EthernetClient &);
195 virtual bool operator!=(const EthernetClient &rhs)
196 {
197 return !this->operator==(rhs);
198 };
208 uint8_t getSocketNumber();
216 virtual uint16_t localPort()
217 {
218 return (_tcp_client->pcb->local_port);
219 };
227 virtual IPAddress remoteIP()
228 {
229 return (IPAddress(_tcp_client->pcb->remote_ip.addr));
230 };
238 virtual uint16_t remotePort()
239 {
240 return (_tcp_client->pcb->remote_port);
241 };
247 void setConnectionTimeout(uint16_t timeout)
248 {
249 _connectionTimeout = timeout;
250 }
251
252 friend class EthernetServer;
253
254 using Print::write;
255
256 private:
257 struct tcp_struct *_tcp_client;
258 bool _owns_tcp_client = false; // true if connect() allocated _tcp_client
259 uint16_t _connectionTimeout = 10000;
260};
261
262#endif
Definition EthernetClient.h:16
virtual void flush()
Sends any data still queued for transmission.
Definition EthernetClient.cpp:184
virtual uint8_t connected()
Checks whether the client is connected.
Definition EthernetClient.cpp:212
virtual int peek()
Returns the next byte without removing it from the buffer.
Definition EthernetClient.cpp:173
EthernetClient()
Default constructor. Creates a client with no connection.
Definition EthernetClient.cpp:19
virtual int connect(IPAddress ip, uint16_t port)
Connects to a remote host by IP address.
Definition EthernetClient.cpp:51
virtual bool operator==(const bool value)
Compares the client's boolean value with a value.
Definition EthernetClient.h:164
uint8_t status()
Returns the state of the TCP connection.
Definition EthernetClient.cpp:219
virtual void stop()
Closes the connection and releases the client structure.
Definition EthernetClient.cpp:193
virtual size_t write(uint8_t b)
Writes one byte to the connection.
Definition EthernetClient.cpp:94
virtual int available()
Returns the number of bytes ready to be read.
Definition EthernetClient.cpp:145
virtual uint16_t localPort()
Returns the local TCP port of the connection.
Definition EthernetClient.h:216
virtual IPAddress remoteIP()
Returns the remote IP address of the connection.
Definition EthernetClient.h:227
uint8_t getSocketNumber()
Returns the socket number, for W5100 compatibility.
Definition EthernetClient.cpp:241
virtual int read()
Reads one byte from the receive buffer.
Definition EthernetClient.cpp:154
virtual bool operator!=(const EthernetClient &rhs)
Tests whether two clients refer to different connections.
Definition EthernetClient.h:195
void setConnectionTimeout(uint16_t timeout)
Sets how long connect() waits for the connection (ms).
Definition EthernetClient.h:247
virtual uint16_t remotePort()
Returns the remote TCP port of the connection.
Definition EthernetClient.h:238
virtual bool operator!=(const bool value)
Compares the client's boolean value with a value.
Definition EthernetClient.h:174
Definition EthernetServer.h:16
Include stm32_eth source files.
Definition stm32_eth.h:77
struct tcp_pcb * pcb
Definition stm32_eth.h:78