Posts: 6
Joined: Sat Dec 15, 2012 9:43 pm
Location: Minnesota, USA

Sockets info

Fri Dec 21, 2012 4:02 pm

Hello all trying to complete a controller project with python I can do everything else needed for it just not receiving my data outta the socket correctly. What did I mess up?

I get this out of my socket


I am connecting on port 24 essentially as a telnet session.
when I use telnet it shows up as


My code is pretty basic for this

Code: Select all

HOST = ''
PORT = 24
rcvData = controller.recv(4096)
obviously if I print it, the info is garbage as far as I am concerned.
Thanks for any help or input.

User avatar
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: Sockets info

Fri Dec 21, 2012 10:15 pm

Great that you are communicating over the socket!

First... As to the data you are receiving - telnet is an intelligent communication protocol. The server expects a connection from a telnet aware client by default. When the connection is established, the server sends out a negotiation sequence to inform the client of the server capabilities and communication parameters to be used.

The "\xff\xfd\x01\xff\xfd\x1f\xff\xfd!\xff\xfb\x01\xff\xfb\x03" sequence is the telnet negotiation from the server to the client. If the client does not respond with an answering sequence, the telnet server will use its defaults. After the telnet negotiation information, the actual ASCII text communication.

It appears you are dumping the "raw" hex representation of the ASCII data.
'\r' - is a carriage return character => move to the beginning of the line for output
'\n' - is a new line character => move to the next line

So, you are receiving the ASCII sequence for

Code: Select all

After "Password:" you are receiving '\r\r\n' to move to the next line. This is not the usual login sequence. I would expect a user prompt followed by the password prompt.

You are seeing this as raw character data on the screen because the line 'rcvData' dumps the variable content without formatting. If you want it interpreted as ASCII characters, you can use:

Code: Select all

print rcvData
The telnet negotiation information will display as "garbage" characters, but you will see the ASCII strings as you expect.

If you want to fully understand the telnet protocol, you can read the relevant RFC 854 Telnet Protocol Specification and others for details about the options.

From the protocol, the server sequence you are receiving is interpreted as:

Code: Select all

  255,253,1   DO ECHO
  255,253,31  DO NAWS (Negotiate About Window Size)
  255,251,1   WILL ECHO
If you ignore the initial server negotiation and you can use simple ASCII communication in most cases.


Posts: 6
Joined: Sat Dec 15, 2012 9:43 pm
Location: Minnesota, USA

Re: Sockets info

Sun Dec 23, 2012 10:54 pm

Thanks for the response. I will read more on the telnet protocol.
print recvData feeds me back nothing that is remotely usable looks close to " ^ ^ ? ^ ^" followed by several new lines. I believe I can get by with the info you have provided.


Return to “Python”