Pages: 1 [2]   Go Down
Author Topic: TelnetClient example  (Read 948 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12577
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the TelnetClient example different from the WebClient example?

There are two differences:

Firstly, you need to connect to the right TCP port on the server. A server could be accepting connections for HTTP, FTP, telnet and so on at the same time, each service provided on a different TCP port. You need to know what port to connect to for the service you want. There are some standard conventions for the ports used by common services, for example telnet is typically on port 23 and HTTP is typically on port 80. You'll see that the telnet and web client examples connect to different TCP ports, and that's why.

Secondly you need to send and receive messages over the connected socket using the appropriate protocol. Telnet and HTTP both happen to be text-based protocols, meaning that the messages consist of printable text that could be entered via a keyboard or displayed on a screen. You'll notice that in the examples you mention, the Arduino doesn't process the messages itself but just passes through anything received from the network to the serial monitor, and vice versa. So the message processing is done by a person reading and typing messages in the serial monitor. You need to enter messages using the correct format for the service you connected to. For example, when you connect to an HTTP service you need to type in a valid HTTP request. Telnet is slightly easier to use in that the telnet protocol just provides a transparent connection between the client (i.e. your Arduino) and a shell processor on the Telnet server, so the commands you need to enter over a Telnet connection are the same ones you would enter to the command shell if you were connected locally.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To be fair to the OP, you can use the telnet client to connect to any server that requires some sort of character-based protocol. A MUD game, for example. In my case I am using a modified version to connect to my "garage door" server. You can fudge up some HTTP in a couple of lines:

Code:
   // if you get a connection, report back via serial:
    if (client.connect (garageDoorServer, garageDoorServerPort))
      {
      
      // request page
      client.println ("HTTP/1.0");
      client.println ("Host: 10.0.0.241");
      client.println ();
 

That requests the root page from 10.0.0.241. It then waits for data to become available. The server in question serves up "plain text" about whether or not the door is open.

As for why you would want a telnet server, I could have replaced the HTTP server with a telnet server, which, once something connects to it, replies "door open" or "door closed" to similar effect. However the advantage of an HTTP server in my case was that I could check the garage door status from any Mac/PC/Linux box/smart phone that had a web browser on it.
Logged

Pages: 1 [2]   Go Up
Jump to: