# How do I send ANSI codes to Telnet, exactly?

## Recommended Posts

Kixdemp    202
Hello everyone! Here's how I'm sending my codes: (After I established a connection and received a character)
SDLNet_TCP_Send(csd, (void*) 0x1B, 1);	// Send ESC char
SDLNet_TCP_Send(csd, (void*) 0x01, 1);	// Send 0x01 (40x25 colors creen)
SDLNet_TCP_Send(csd, (void*) 0x42, 1);	// Green background
SDLNet_TCP_Send(csd, buffer, 1);	// Send my char


But only the last one gets sent! (On WinXP's Telnet client, it gets sent twice, so I'm using Win98's) Why is it? I have a feeling this is not how you do it... Any ideas? Thanks!

##### Share on other sites
Nice Coder    366
you send 0x1B [ 0x01 0x42

You've forgotten the [

##### Share on other sites
markr    1692
You can't cast 0x1B to a void * and expect it to work.

I imagine that SDLNet_TCP_Send requires a pointer to a buffer. 0x1B is not a pointer to a buffer containing the value 0x1B, it's the value 0x1B itself. If you attempt to dereference this pointer it will certainly fail.

I'm really surprised your code doesn't crash.

Mark

##### Share on other sites
Kixdemp    202
Hmm... Still not working...

Here's what I'm doing now:

char sm[5];/* Function goes here, doesn't mess with sm at all */sm[0] = (char) 0x1b;sm[1] = '[';sm[2] = '=';sm[3] = (char) 4;sm[4] = 'h';SDLNet_TCP_Send(csd, sm, 5); // Send escape sequenceSDLNet_TCP_Send(csd, buffer, 1); // Send my char

By that I'm trying to change the screen mode to 320x200 color... Am I doing something wrong or what? Thanks!

PS: I'm using PuTTY on Win98.

##### Share on other sites
Kylotan    9854
Assuming that is transmitted correctly, you're not going to find a basic telnet client that will give you any non-text modes. For that you'll probably need one of the old X clients. I seem to remember 'Exceed' being one of them, back from my long distant days on Sun Sparc stations. If a graphical mode is a requirement of your project, you should probably give up on the telnet/ANSI route.

##### Share on other sites
Kixdemp    202
No, I don't want graphics, I just want color text. [wow]

Any other ideas? Thanks!

##### Share on other sites
Kylotan    9854
The code you're sending isn't for colour text though. It's for changing the screen mode. Send the actual ANSI code for foreground text colour changes and see what happens.

##### Share on other sites
hplus0603    11347
Putty and Xterm are already in color text screen mode. However, depending on mode, you may need to send VT-100 codes instead of ANSI codes in some cases -- try each and see what happens.

##### Share on other sites
Kixdemp    202
Yeah, I figured it out... :grin:
Now, how can I check which Telnet client the user is running? Because for example, Windows Telnet sends info when a character is pressed, but PuTTY only sends it when Enter is pressed! Do you know? Thanks!

##### Share on other sites
hplus0603    11347
Putty sends the character as soon as you press the key. If you observe a difference, it must come from elsewhere -- unless you somehow have set Putty to "line mode" or something similar.

Detecting which terminal emulation is at the other end is pretty hard, even though it's been a problem for 30 years. The best you can do is use the TELNET standard for terminal type negotiation (it's among the TELNET protocol escape codes) and hope the client complies.

Or just ask the user when they log on.