Feedback on telnet/tcp server

Hello,

I modified the telnet server from this place: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278686415/2

But i'm not too good at this, and need some feedback.
Do i handle request correct? do i close connections on the right time? .....

I will mostly connect from a php script, and send a command to the arduino.

Here is the code: http://www.copypastecode.com/46008/

Any feedback will be appreciated. :slight_smile:

Have you actually tested your code? If so, did it work?

yes, it works.

But i have som problems i cant figure out.

If i use this php command to send commands, it works great:

            $fp = fsockopen("192.168.1.101", 23, $errno, $errstr, 10);
            if (!$fp) {
                $returning = "$errstr ($errno)";
            } else {
                fwrite($fp, $command);
                while (!feof($fp)) {
                    $returning = fgets($fp, 30);
                }
                fclose($fp);
            }

But if i try to send something from a shell with netcat, like: printf 'p30' | nc -v -w 5 192.168.1.101 23
It will only work one time, then i have to restart the arduino.
So i guess it doesnt close the connection correctly or something? :-/
But i don't know if it netcats fault, or if it's the arduinos