禁用 Java 网络连接上的字符回显

发布于 2024-07-09 22:44:05 字数 345 浏览 5 评论 0原文

我有一个用 Java6 编写的 Solaris 守护程序。 客户端可以使用 telnet 风格的界面连接到它。 他们远程登录到特定端口,我读取输入行并对其进行操作。

在某一时刻,我需要提示用户输入密码,当他们输入密码时,我想禁用字符回显到 telnet 客户端。

该代码有一个 Socket 对象,并从套接字的 getInputStream() 结果创建一个 InputStream,然后从 InputStream 读取并缓冲字符,在 cr/lf 边界上将它们分解。

我在 InputStream 或 Socket 上看不到任何属性来禁用字符回显给客户端。

有人可以把我推向正确的方向吗?

I have a Solaris daemon written in Java6. Clients can connect to it using a telnet style interface. They telnet to a particular port, and I read lines of input and act on them.

At one point in I need to prompt the user to enter a password, and while they're entering that I want to disable the echoing of characters back to the telnet client.

The code has a Socket object and creates an InputStream from the socket's getInputStream() result, then reads and buffers characters from the InputStream, breaking them up on cr/lf boundaries.

I can't see any attributes on either the InputStream or the Socket to disable the echoing of characters back to the client.

Can someone nudge me in the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

姐不稀罕 2024-07-16 22:44:06

听起来您需要构建一个简单的网络虚拟终端来支持 no echo 等命令。 SO 上已经有一个很好的答案了:Telnet Server

Sounds like you need to build a simple Network Virtual Terminal that supports the no echo etc commands. There is already a good answer you should refer to on SO : Telnet Server

无法回应 2024-07-16 22:44:06

您应该了解回声是从哪里来的。 TCP 连接和 java InputStreams 本身不提供回显。 用户运行的telnet程序通常以“本地回显”模式启动,这意味着它将用户输入的所有内容回显到用户的屏幕上。 当 telnet 客户端连接到实际的 telnet 服务器时,它通常协商“远程回显”模式,在这种情况下,远程系统提供回显。 当 telnet 连接到其他服务器(例如 HTTP 或 SMTP 服务器)时,它只会保持本地回显模式。

用户可以发出命令来关闭客户端中的本地回显,但要求用户这样做并不是非常用户友好。 正如另一个答案所说,如果您想打开和关闭回显,您将需要增强服务器以支持 telnet 协议,然后与客户端协商远程回显。

如果这样做,您还会遇到一次一行与一次字符的问题。 Telnet 以一次一行模式启动。 它在本地支持诸如退格键之类的行编辑键,并且仅在用户按回车键时才将行发送到服务器。 如果您正在进行远程回显,那么您需要在用户键入字符时回显字符,而不是在他按回车键后回显。 因此,您必须支持一次字符并在服务器中实现行编辑。

您应该仔细查看服务器主机上的 telnet 服务器程序。 可以使用现有的 telnet 服务器作为程序的前端,而不是重新实现它所做的一切。 祝你好运。

You should understand where the echo is coming from. TCP connections and java InputStreams don't provide echo on their own. The telnet program that the user runs normally starts in "local echo" mode, meaning that it echoes everything typed by the user to the user's screen. When the telnet client connects to an actual telnet server, it commonly negotiates "remote echo" mode in which case the remote system provides the echo. When telnet connects to something else, like an HTTP or SMTP server, it just stays in local echo mode.

The user can issue a command to turn off local echo in the client, but it wouldn't be very user-friendly to require your users to do that. As the other answer says, if you want to switch echoing on and off, you will need to enhance your server to support the telnet protocol, then negotiate remote echo with clients.

If you do this, you'll also encounter the issue of line-at-a-time vs. character-at-a-time. Telnet starts in line-at-a-time mode. It honors line-editing keys like backspace locally, and only sends the line to the server when the user hits return. If you're doing remote echo, then you need to echo characters as the user types them, not after he hits return. So you'll have to support character-at-a-time and implement line editing in the server.

You should look closely at the telnet server program on your server host. It might be possible to use the existing telnet server as a frontend for your program, rather than reimplementing everything that it does. Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文