Ethernet shield server.write vs server.print

What is the difference between server.write() and server.print()?

This is pretty clearly documented.

write() server.write(data) data: the value to write (byte or char)

print() server.print(data) server.print(data, BASE) data: the data to print (char, byte, int, long, or string)

The documentation is clear as mud, in this instance (really good overall!!!). The only difference I see is that you can use the optional 'BASE' in server.print. Also, using server.print, it seems I have more flexibility as to what 'DATA' can hold. I've read the ethernet reference, several times. The reason I asked the question is because server.write and server.print seem to be almost interchangeable. Am I missing something, or is that pretty much correct?


Print data to all the clients connected to a server. Prints numbers as a sequence of digits, each an ASCII character (e.g. the number 123 is sent as the three characters ‘1’, ‘2’, ‘3’).

Sounds like the print function can take a single byte and convert it into various multi character formats.

Just always use print, and it will do what you expect. They should have hidden write(). If you call print(32), you will get '32'. If you call write(32) you will get a space (' ') and be confused.

They should have hidden write()

Since the Client class derives from Stream, which derives from Print, and the Server class derives from Print, this would have been impossible, since both print() and write() are public methods in the Print class. Serial also derives from Print, and in Serial you most definitely want to be able to send both ASCII (“32”) and binary (32) data.

It would have taken a little bit of work, but definitely possible. Server could have derived privately from Print and then thoughtfully exposed only the interface that’s needed to users.