can't connect using telnet client and laptop as server

hi,

I have a problem to connect arduino uno via ethernet shield using telnet communication. I’m using telnet client example and i wonder to use my laptop as server.

I’m using ubuntu 16.04 and i already using this command at the terminal telnet 192.168.1.3 10002 and the output is Trying 192.168.1.3…

and then i connect the ethernet cable to my computer and the shield, then i connect arduino to my laptop. I see the serial saying
connecting…
connection failed,
disconnecting.

here is my code :

/*
  Telnet client
 
 This sketch connects to a a telnet server (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.  You'll need a telnet server 
 to test this with.
 Processing's ChatServer example (part of the network library) works well, 
 running on port 10002. It can be found as part of the examples
 in the Processing application, available at 
 http://processing.org/
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 14 Sep 2010
 modified 9 Apr 2012
 by Tom Igoe
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,3);

// Enter the IP address of the server you're connecting to:
IPAddress server(192,168,1,2); 

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use  port 10002):
EthernetClient client;

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 10002)) {
    Serial.println("connected");
  } 
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // as long as there are bytes in the serial queue,
  // read them and send them out the socket if it's open:
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar); 
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while(true);
  }
}

please help, i appreciate it.
Thanks

Did you install the telnet server?

sudo apt-get install xinetd telnetd

Did you change the default port for telnet in /etc/services? Normally it is 23.

yes i did.

Network services, Internet style

Note that it is presently the policy of IANA to assign a single well-known

port number for both TCP and UDP; hence, officially ports have two entries

even if the protocol doesn't support UDP operations.

Updated from Service Name and Transport Protocol Port Number Registry and other

sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services .

New ports will be added on request if they have been officially assigned

by IANA and used in the real-world or are needed by a debian package.

If you need a huge list of used numbers please install the nmap package.

tcpmux 1/tcp # TCP port service multiplexer
echo 7/tcp
echo 7/udp
discard 9/tcp sink null
discard 9/udp sink null
systat 11/tcp users
daytime 13/tcp

i can't find the port for telnet

If you didn’t find or change it, then telnet is on port 23.

Thanks four your reply.
I already change the port in this line of code

if (client.connect(server, 23)) {
    Serial.println("connected");
  }

but still can’ connect :frowning:

Can you connect from the laptop? Open a terminal and:
telnet 192.168.1.2

Insure you are using the correct ip. From the terminal:
ifconfig

i followed your instruction but still can't connect it to my laptop

here the screenshot of my laptop:

I'm so confused.

Thank you so much for your patience

If you can't telnet to your laptop from your laptop, you haven't installed telnet correctly. I have Ubuntu 16.10 with telnet, and it connects to itself, and the Arduino connects to it with your code using port 23.

edit: you must reboot your laptop after the telnet install.

oh i miss understand there. what i did before is like from this image Google Drive: Sign-in

i don't know how to telnet to my laptop itself :s

and this is my sudo /etc/init.d/xinetd status :

xinetd.service - LSB: Starts or stops the xinetd daemon.
   Loaded: loaded (/etc/init.d/xinetd; bad; vendor preset: enabled)
   Active: active (running) since Min 2017-02-12 02:05:25 WIB; 25min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1149 ExecStart=/etc/init.d/xinetd start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/xinetd.service
           └─1178 /usr/sbin/xinetd -pidfile /run/xinetd.pid -stayalive -inetd...

Peb 12 02:05:25 bles xinetd[1178]: removing daytime
Peb 12 02:05:25 bles xinetd[1178]: removing daytime
Peb 12 02:05:25 bles xinetd[1178]: removing discard
Peb 12 02:05:25 bles xinetd[1178]: removing discard
Peb 12 02:05:25 bles xinetd[1178]: removing echo
Peb 12 02:05:25 bles xinetd[1178]: removing echo
Peb 12 02:05:25 bles xinetd[1178]: removing time
Peb 12 02:05:25 bles xinetd[1178]: removing time
Peb 12 02:05:25 bles xinetd[1178]: xinetd Version 2.3.15 started with libwr...n.
Peb 12 02:05:25 bles xinetd[1178]: Started working: 0 available services
Hint: Some lines were ellipsized, use -l to show in full.

Open a terminal on the laptop. Enter this:
telnet 192.168.1.2

Are you certain the laptop has the IP 192.168.1.2? I don't see that on your image. I see 192.168.43.82.

this image is updated : Google Drive: Sign-in

If you can't telnet into the laptop from the laptop, your telnet server setup is faulty, not the Arduino code.