Searching for arduino println library

Hello everyone,

First time poster here. I hope this question is in the right section.

I have been looking into the Arduino Ethernet libraries and trying to see how things work. I have spent some time following the sample server code:

and tracing each line of code to correspond with the socket state machine from the Wiznet datasheet along with the ethernet libraries provided here:

https://github.com/arduino/Arduino/tree/master/libraries/Ethernet/

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.

It’s defined in arduinodir/hardware/arduino/cores/arduino/Print.h on Linux - where arduinodir is you install dir

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?

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.

Korman

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.

The converse is not true, however.

Korman, your example makes sense. Can you help me point out where this applies to the Client class?

class Client : public Print

Pauls, just wondering does this line of code exist somewhere I am not looking? I can not seem to find it.

This means that a Client instance IS a Print instance with extra capabilities/data.

And can you possibly help me point out where these extra capabilities are defined for Client?

Thanks again guys for the help.

just wondering does this line of code exist somewhere I am not looking? I can not seem to find it.

That line was copied from Client.h.

And can you possibly help me point out where these extra capabilities are defined for Client?

Look in Print.h and Print.cpp in \hardware\arduino\cores\arduino.