I can not find anywhere in the libraries where client.print() is defined. Client.print() seems to be used frequently and is relevant to the function of sending over Ethernet. Upon looking at the Ethernet libraries, I have also gone through the core libraries and have still found nothing. Can anyone shed some light on this? Any help would be appreciated. Thanks!
Look at the declaration of the Client class? See that it derives from another class? Perhaps the class that it derives from will give you a clue where to look.
Thanks for the replies. The one underlying question I can't seem to solve is how Client class and this print class are linked. How is it that Client can call print? Like in the sample code above, client.print() or client.println(). Does anyone have an answer for this?
If you want a working example, look at the definition for Serial in HardwareSerial.h. The interesting part is:
class HardwareSerial [glow]: public Stream[/glow]
{
private:
...
public:
HardwareSerial(ring_buffer *rx_buffer,
...
virtual void write(uint8_t);
[glow]using Print::write;[/glow] // pull in write(str) and write(buf, size) from Print
};
All printing in print and println from class Print is done via the virtual function write, which gets pulled into your new class, which needs to be a child class of Print (in this case via Stream) and override the write function. For more details look for “class inheritance”, “virtual functions” and “using declaration” in your favourite C++ reference.
The Client/Print case is even easier to explain. The Client class derives from the Print class.
class Client : public Print
This means that a Client instance IS a Print instance with extra capabilities/data. So, anything a Print instance can do, a Client instance can do, too.