Redirect Serial.print() to telnet clients with checking

I modified a command line interface from https://github.com/fakufaku/CmdArduino to support telnet clients ...

Now that the telnet client is it working, I had to add telnetClient.print() line to EVERY Serial.print() & Serial.println() statements in my codes ...

Is there a more efficient way to send to an intermediate function that will check if telnet client isConnected and only send to those telnet client, the default is still send to the Serial.print

Any advise or suggestions are welcome and appreciated ...

stan001:
Now that the telnet client is it working, I had to add telnetClient.print() line to EVERY Serial.print() & Serial.println() statements in my codes ...

are you saying you modified the CmdArduino library to instead redirect to the telnet connection instead of Serial?

It seems to me that creating a function that checks for a Telnet connection and then either prints to Serial or to the client is somewhat trivial.

Serial and EthernetClient are both Stream devices. Setup a pointer to Stream, and set the pointer to either &Serial or &client, and use that pointer to print.

Stream *console;
...
if (serialConsole)
    console = &Serial;
else
    console = &client;
...
console->print("Print this\n");

Regards,
Ray L.

I have it for esp8266. modify it for your networking library.

TelneStream

Thanks for all the replies...

The keyword I was looking for is Stream ..

After looking at the Cmd Arduino forks, someone had already implemented it ...

stan001:
Thanks for all the replies...

The keyword I was looking for is Stream ..

After looking at the Cmd Arduino forks, someone had already implemented it ...

Hi Stan, would you please point me to the exact fork that you found?
Thanks