Hey, guys!

I am trying to figure out, how to use the Teensy 4.1 as a telnet server. After long research I haven't found an example or solution for my problem, yet. I'm pretty new to programming in Arduino. So please don't judge me too fast.

My thoughts were to use the Teensy 4.1 as a telnet server, connecting via ethernetcable to a laptop. The laptop should simulate the client. At first I want to try to send simple messages from the Laptop to the Teensy (via Putty). I created some stuff the Teensy should do when I text him.
I already activated the Telnet Client on the laptop and deactivated the firewalls.
The project is a lot larger than the part I show here. So I created an example to show you my problem.

First of all: Is it possible to use Teensy 4.1 as a Telnet server? If not, is there another way I could get a communication?
Do I have to specify the software to use telnet?


The problem I have is, if I ask for the client IP (laptop) it always tells me that the IP was 0.0.0.0. So my program isn't even able to come as far that I can communicate.
I have no more ideas how to get the Teensy 4.1 to give me the right IP...


I use Teensyduino 1.53, Arduino 1.8.13, Teensy 4.1, the latest Putty version, the latest verisons of NativEthernet and Fnet and an old Windows 7 laptop.


Code:

Code:
#include <stdlib.h>
#include <TimerOne.h>
#include <SPI.h>
#include <fnet.h>
#include <NativeEthernet.h>

#define SPI_MOSI        11
#define SPI_MISO        12
#define SPI_SCK         13
#define SPI_FREQ  1000000                                 //SPI frequency (1 MHz)
static  SPISettings spi_settings                          //SPI settings
        = SPISettings(SPI_FREQ, MSBFIRST, SPI_MODE1);

byte mac[] = {
  0x92, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(169, 254, 86, 246);
IPAddress subnet(255, 255, 0, 0);
IPAddress serv(169, 254, 86, 215);
IPAddress gateway(169, 254, 86, 1);

EthernetServer server(23);

EthernetClient client = server.available();

boolean alreadyConnected = false;

String inputString;
String inputCommand;
byte buf[1024];

uint8_t msg_received = 0;
uint8_t msg_send = 0;

float temperatures[] = {5, 4.3, 1234, 23, 1.23, -5.0000034};

bool alarm = true;


void setup() {

  Serial.begin(115200);
  Serial.println("Server online!");


  SPI.setMISO(SPI_MISO);                                     //set MISO pin
  SPI.setMOSI(SPI_MOSI);                                     //set MOSI pin
  SPI.setSCK(SPI_SCK);                                       //set clock pin
  SPI.begin();                                            //start SPI bus

  Ethernet.begin(mac, ip, gateway, subnet);
  if(Ethernet.hardwareStatus() == EthernetNoHardware){
    Serial.println("Ethernet is not available. Check hardware status!");
    while(true){;}
  }
  if(Ethernet.linkStatus() == LinkOFF){
    Serial.println("Ethernet cable is not connected");
  }
  server.begin();
  Serial.print("Server IP-address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {

  if(client){
    new_client();
    communication();
  }

  control_interface();
}


void print_command_list(){
  Serial.println("Command list:");
  Serial.println("");
}

void new_client(){
  if(!alreadyConnected){
    client.flush();
    Serial.println("New Client available.");
    Serial.print("Client IP: ");
    Serial.println(client.remoteIP());
    client.println("Hello, client!");
    client.print("Server IP: ");
    client.println(ip);
    client.println(Ethernet.localIP());
    alreadyConnected = true;
  }
}


void communication(){

  if(client.available() > 0){
    
    char thisChar = client.read();
    inputCommand = client.readString();
//    server.write(thisChar);
//    Serial.write(thisChar);


    switch(thisChar){
      
      case 'temp':
        for(int i=0; i<6; i++){
          server.write(temperatures[i]);
          client.print(temperatures[i]);
          client.print("  ");
        }
        Serial.println("All temperature values have been sent.");
        client.println();
      break;

      case 'reads':
        inputString = client.readString();
        Serial.print(inputString);
//        client.write(inputString);
        server.write("Danke für die Nachricht ;)");
      break;

      case 'h':
        print_command_list();
        server.write("Command list has been print to Serial\r\n");
      break;

      case 'a':
        server.write(alarm);
        client.print("Alarmstatus: ");
        client.print(alarm);
      break;

      case 'b':
        server.write("Achtung, ich gebe dir den Alarm-Status zurück!");
        thisChar = 'a';
      break;
      
      case 'runs':
        server.write("deep, run wild");
      break;

      case 'traffic':
        while(client.connected()){
          client.read(buf,1024);
        }
        client.stop();
        Serial.println("Client disconnected");
      break;

      default:
        server.write("No valid input");
      break;

    }

    }
}


void control_interface(){

  String input = "";

  if(Serial.available() > 0){
    input = Serial.readString();
    msg_send = (input.substring(0,4)).toInt();
    Serial.print("Zu sendende Nachricht: ");
    Serial.println(msg_send);
  }
  
}

This is the output in the serial monitor:

Code:
Server IP-address: 169.254.86.246

New Client available.

Client IP: 0.0.0.0


I saw that my variables in the switch-case are too long or have the wrong data typ, please ignore the fact, I will change that later on.

I really would appreciate if you guys could help me!
Thank you!