MySensors Library & Examples  2.3.2-36-g2e00bf6
EthernetClient.h
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2020 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  *
19  * Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
20  */
21 
22 #ifndef EthernetClient_h
23 #define EthernetClient_h
24 
25 #include "Client.h"
26 #include "IPAddress.h"
27 
28 // State codes from W5100 library
29 #define ETHERNETCLIENT_W5100_CLOSED 0x00
30 #define ETHERNETCLIENT_W5100_LISTEN 0x14
31 #define ETHERNETCLIENT_W5100_SYNSENT 0x15
32 #define ETHERNETCLIENT_W5100_SYNRECV 0x16
33 #define ETHERNETCLIENT_W5100_ESTABLISHED 0x17
34 #define ETHERNETCLIENT_W5100_FIN_WAIT 0x18
35 #define ETHERNETCLIENT_W5100_CLOSING 0x1A
36 #define ETHERNETCLIENT_W5100_TIME_WAIT 0x1B
37 #define ETHERNETCLIENT_W5100_CLOSE_WAIT 0x1C
38 #define ETHERNETCLIENT_W5100_LAST_ACK 0x1D
39 
43 class EthernetClient : public Client
44 {
45 
46 public:
56  explicit EthernetClient(int sock);
64  virtual int connect(const char *host, uint16_t port);
72  virtual int connect(IPAddress ip, uint16_t port);
79  virtual size_t write(uint8_t b);
87  virtual size_t write(const uint8_t *buf, size_t size);
94  size_t write(const char *str);
102  size_t write(const char *buffer, size_t size);
108  virtual int available();
114  virtual int read();
122  virtual int read(uint8_t *buf, size_t bytes);
128  virtual int peek();
132  virtual void flush();
138  virtual void stop();
144  uint8_t status();
153  virtual uint8_t connected();
157  void close();
161  void bind(IPAddress ip);
167  int getSocketNumber();
173  virtual operator bool();
178  virtual bool operator==(const bool value)
179  {
180  return bool() == value;
181  }
186  virtual bool operator!=(const bool value)
187  {
188  return bool() != value;
189  }
194  virtual bool operator==(const EthernetClient& rhs);
199  virtual bool operator!=(const EthernetClient& rhs)
200  {
201  return !this->operator==(rhs);
202  };
203 
204  friend class EthernetServer;
205 
206 private:
207  int _sock;
208  IPAddress _srcip;
209 };
210 
211 #endif
EthernetClient::operator!=
virtual bool operator!=(const bool value)
Overloaded cast operators.
Definition: EthernetClient.h:186
EthernetClient::connected
virtual uint8_t connected()
Whether or not the client is connected.
EthernetClient
Definition: EthernetClient.h:43
EthernetClient::operator!=
virtual bool operator!=(const EthernetClient &rhs)
Overloaded cast operators.
Definition: EthernetClient.h:199
EthernetClient::close
void close()
Close the connection.
EthernetClient::peek
virtual int peek()
Returns the next byte of the read queue without removing it from the queue.
EthernetClient::connect
virtual int connect(const char *host, uint16_t port)
Initiate a connection with host:port.
EthernetClient::status
uint8_t status()
Connection status.
EthernetClient::write
virtual size_t write(uint8_t b)
Write a byte.
EthernetClient::flush
virtual void flush()
Waits until all outgoing bytes in buffer have been sent.
EthernetClient::getSocketNumber
int getSocketNumber()
Get the internal socket file descriptor.
EthernetClient::bind
void bind(IPAddress ip)
Bind the conection to the specified local ip.
EthernetServer
EthernetServer class.
Definition: EthernetServer.h:42
EthernetClient::read
virtual int read()
Read a byte.
EthernetClient::EthernetClient
EthernetClient()
EthernetClient constructor.
IPAddress
A class to make it easier to handle and pass around IP addresses.
Definition: IPAddress.h:32
EthernetClient::stop
virtual void stop()
Close the connection gracefully.
EthernetClient::operator==
virtual bool operator==(const bool value)
Overloaded cast operators.
Definition: EthernetClient.h:178
EthernetClient::available
virtual int available()
Returns the number of bytes available for reading.