24

I am trying to send commands to a server via a python script. I can see the socket connection being established on the server. But the commands I am sending across , do not seem to make it through(server does a read on the socket). The server currently supports a telnet command interpreter. ie: you telnet to the command address and port, and you can start sending string commands. My question is , is there anything fundamentally different from sending strings over a tcp socket, as opposed to using telnet. I have used both raw sockets as well as the Twisted framework.

1
  • The difference is the same as the difference between a car and an engine. Telnet may be implemented using TCP sockets, just like a car may be built using a specific type of engine.
    – wroniasty
    Oct 4, 2012 at 15:18

3 Answers 3

24

Telnet is a way of passing control information about the communication channel. It defines line-buffering, character echo, etc, and is done through a series of will/wont/do/dont messages when the connection starts (and, on rare occasions, during the session).

That's probably not what your server documentation means. Instead, it probably means that you can open a TCP socket to the port using a program like "Telnet" and interact with a command interpreter on the server.

When the Telnet program connects, it typically listens for these control messages before responding in kind and so will work with TCP/socket connections that don't actually use the telnet protocol, reverting to a simple raw pipe. The server must do all character echo, line buffering, etc.

So in your case, the server is likely using a raw TCP stream with no telnet escape sequences and thus there is no difference.

5
  • python is brilliant that way. there is a telnetlib.
    – Pradyot
    Oct 4, 2012 at 16:19
  • @Brian_White, could you provide a doc reference for "reverting to a simple raw pipe"?
    – 1.61803
    Jun 19, 2016 at 19:12
  • 1
    I'm not sure that it is part of any RFC. The statement comes from my experience writing a telnet client and comparing it to the behavior of existing clients, hence the "typical" qualifier. Of course, it won't be completely raw because the IAC character can't be passed directly but that generally isn't a problem for a console user interface. You can check it yourself by using telnet to connect to any open port (e.g. web port 80) and observe that no IAC control sequences are sent by the client. Jun 21, 2016 at 11:54
  • I didn't understand the third sentence. If I trace the connection, it seems raw.
    – 1.61803
    Aug 4, 2016 at 22:02
  • 1
    Assuming you mean the third paragraph: The only difference would be some control sequences embedded in the stream. IAC FOO BAR (in binary, not ascii) If the server never sends them (and many systems do not) then you will have something very similar to a raw connection. I say "similar" because it isn't fully 8-bit clean; any IAC (0xFF) characters should be escaped as IAC IAC. Aug 8, 2016 at 15:25
12

Keep in mind that Telnet is an application layer protocol while TCP is a transport layer protocol. Telnet uses TCP in order to transmit data. That is a big fundamental difference between Telnet and TCP.

See: OSI Model wikipedia page

4

From the Wikipedia page on telnet

...User data is interspersed in-band with Telnet control information...

So, to answer your question, yes, telnet does differ from a raw socket.

RFC 854 describes the telnet protocol if you want to try implementing it or you could use telnetlib if you'd prefer an existing python client.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.