How to read data from telnet and use it?

Hey guy, i am a student from Hong Kong, so please don't care about my suck english :cry:

I would like to read a data from telnet, and use it for "if else" statement in my program, but seem had some problem when i try to do it, i wonder if there the "client.read()" function is read the data by byte format and also store it in char by byte format too? so that the data can't use to compare with other? :cry:

Here is the code for express what i was planing to do

#include <SPI.h>

/*
 * Chat Server
 *
 * A simple server that distributes any incoming messages to all
 * connected clients.  To use telnet to 10.0.0.177 and type!
 */

#include <Ethernet.h>

// network configuration.  gateway and subnet are optional.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 11, 177 };
byte gateway[] = { 192, 168, 11, 254 };
byte subnet[] = { 255, 255, 255, 0 };

char test;

// telnet defaults to port 23
Server server(23);

void setup()
{
  // initialize the ethernet device
  // Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet);

  // start listening for clients
  server.begin();
}

void loop()
{
  Client client = server.available();
  if (client) {
   test = client.read();
     // even i had type in 1 in telnet, the following decide not working...
          if (test == 1) {
          client.println("you're type in 1!\n");
          } else {
          client.println("you're type in 0!\n");
          } 
  }          
}

i know my question maybe so simple for yours, and i was successful to run the telnet control program which writing by other people, i know that the data read from telnet can use for decide somethings in the program, but i don't know how can do it :cry:

Timothy,

The problem with telnet is that it sends extra bytes to control the connection.

If you use a different port from 23, it will not send the extra bytes.

Regards,

-Mike

it works ::slight_smile:
you're my man :-[

Mike, but i was see other people who can use port 23 to make a telnet remote control, why they can do it?

just say this gay...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278686415/2

Timothy,

I do not know how theirs works with port 23. It is possible to use an option on some telnet clients to turn off the control information.

If you want to learn all about the control information, google for "telnet rfc". I have written telnet clients and servers, and handling that stuff is not fun.

Regards,

-Mike