Tcpclient.available() == 0 until telnet client hits ENTER [SOLVED]

I’m finding that when I connect to my Spark using putty telnet, I have to hit ENTER on my client before data sent to the server is shown as available. The code below uses ‘1’ to turn on the LED, ‘0’ to turn it off, and ‘q’ to close the session. I verified with Wireshark that the ‘1’ is sent immediately on keypress, and the ENTER (technically CR/LF) sent in the next telnet packet, but the ‘1’ doesn’t make it to my app until the ENTER. I’d like to get the ‘1’ immediately, without requiring the ENTER.

// init vars
TCPServer server = TCPServer(23);
TCPClient client;

void setup()
    // set led as output
    pinMode(D7, OUTPUT);

    // start server

void loop()
    char c;
    if (client.connected())
        // loop until data stops
        while (client.available())
            // handle keypress events
            switch (c = (char)
                case '1':
                    // 1 turns on
                    digitalWrite(D7, HIGH);
                case '0':
                    // 0 turns off
                    digitalWrite(D7, LOW);
                case 'q':
                    // q quits
                    // Reconnect to the cloud when telnet is disconnected
        // wait for new connections
        client = server.available();
        // When my telnet client connects, disconnect from the cloud
        if ( client.connected() ) {

Sounds like the client is in line buffered mode, since you don’t have a full telnet client to negotiate character mode.

I can’t see an option to explicitly do that on my putty client, but forcing local line editing off in the terminal settings might help.


Well I’ll be - that’s it. “Local line editing” set to “Force off” and all better. Thanks @AndyW !!