Search code examples
tcparraystelnet

What are the first 4 Strings received on telnet connection?


I'm emulating a telnet server for my application. When I connect to my app via telnet(just using putty to connect locally) I always receive these 4 sequences on initial connect.

    ByteString(-1, -5, 31, -1, -5, 32, -1, -5, 24, -1, -5, 39, -1, -3, 1, -1, -5, 3, -1, -3, 3),
    ByteString(-1, -2, 31, -1, -2, 32, -1, -2, 24, -1, -2, 39, -1, -4, 1),
    ByteString(-1, -5, 36),
    ByteString(-1, -2, 36)

I figured, the connection is established successfully if I return these back to client. But I'd rather know what these are and how and if I should handle them differently.

Thanks


Solution

  • They are Telnet command sequences.

    -1 -5 31 = IAC WILL NAWS
    -1 -5 32 = IAC WILL TERMINAL-SPEED
    -1 -5 24 = IAC WILL TERMINAL-TYPE
    -1 -5 39 = IAC WILL NEW-ENVIRON
    -1 -3 1  = IAC DO   ECHO
    -1 -5 3  = IAC WILL SUPPRESS-GO-AHEAD
    -1 -3 3  = IAC DO   SUPPRESS-GO-AHEAD
    -1 -2 31 = IAC DONT NAWS
    -1 -2 32 = IAC DONT TERMINAL-SPEED
    -1 -2 24 = IAC DONT TERMINAL-TYPE
    -1 -2 39 = IAC DONT NEW-ENVIRON
    -1 -4 1  = IAC WONT ECHO
    -1 -5 36 = IAC WILL ENVIRON
    -1 -2 36 = IAC DONT ENVIRON
    

    Read RFC 854, RFC 855 and other related RFCs that define the Telnet protocol and its various options (there are a lot of them).