You have to send the right byte sequence to the client to tell it to suppress local echo. These are described in RFC857.
I looked through a lot of resources on how to accomplish this and it's not very straightforward. This is what ended up working, though:
require 'socket'
server = TCPServer.open(2000)
client = server.accept
# Send the IAC DONT ECHO byte sequence
client.write "#{255.chr}#{254.chr}#{1.chr}"
# Send the IAC WILL ECHO byte sequence
client.write "#{255.chr}#{251.chr}#{1.chr}"
client.write 'Enter any text and it will not echo locally: '
text = client.gets.chomp
client.write "\r\n"
client.write "The text entered while echo was suppressed was #{text}\r\n"
# Send the IAC DO ECHO byte sequence
client.write "#{255.chr}#{253.chr}#{1.chr}"
# Send the IAC WONT ECHO byte sequence
client.write "#{255.chr}#{252.chr}#{1.chr}"
client.write 'Local echo has been re-enabled, enter any text: '
client.gets.chomp
client.close
The output in the telnet client is:
telnet localhost 2000
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Enter any text and it will not echo locally:
The text entered while echo was suppressed was foo
Local echo has been re-enabled, enter any text: bar
Connection closed by foreign host.
This solution is dependent upon the client telnet application supporting these modes and respecting them when they are requested. There is no guarantee that the client will honor them.