java - Telnet session 与 TCP session

标签 java sockets session tcp telnet

TELNETTCP session 之间有什么区别? 我有一个简单的服务器:

public static void main(String[] args) throws IOException {
    ServerSocket ss = new ServerSocket(5555);
    Socket socket = ss.accept();
    System.out.println("Waiting for a client...");
    InputStream sin = socket.getInputStream();
    OutputStream sout = socket.getOutputStream();
    DataOutputStream out = new DataOutputStream(sout);
    out.writeUTF("\u001B[2J");
    out.writeUTF("Hello client\r\n");
    while (true) {
        int b = sin.read();
        sout.write(b);
    }
}

我通过 telnet 连接并输入如下内容:

enter image description here

因此,我假设 telnet 客户端发送的数据包没有特定的 header ,并且完全不改变地传递到低级协议(protocol)(在我的情况下是 TCP)。正确吗?

最佳答案

来自http://en.wikipedia.org/wiki/Telnet#Telnet_data :

All data octets except 0377 are transmitted over the TCP transport as is. Therefore, a Telnet client application may also be used to establish an interactive raw TCP session, and it is commonly believed that such session which does not use the IAC (0377 character, or 255 in decimal) is functionally identical.[citation needed] This is not the case, however, because there are other network virtual terminal (NVT) rules, such as the requirement for a bare carriage return character (CR, ASCII 13) to be followed by a NULL (ASCII 0) character, that distinguish the telnet protocol from raw TCP sessions.[clarification needed] On the other hand, many systems now possess true raw TCP clients, such as netcat or socat on UNIX and PuTTY on Windows, which also can be used to manually "talk" to other services without specialized client software. Nevertheless, Telnet is still sometimes used in debugging network services such as SMTP, IRC, HTTP, FTP or POP3 servers, to issue commands to a server and examine the responses, but of all these protocols only FTP really uses Telnet data format.

Another difference of Telnet from a raw TCP session is that Telnet is not 8-bit clean by default. 8-bit mode may be negotiated, but high-bit-set octets may be garbled until this mode was requested, and it obviously will not be requested in non-Telnet connection. The 8-bit mode (so named binary option) is intended to transmit binary data, not characters though. The standard suggests the interpretation of codes 0000–0176 as ASCII, but does not offer any meaning for high-bit-set data octets. There was an attempt to introduce a switchable character encoding support like HTTP has,[3] but nothing is known about its actual software support.

我会再输入一些内容,但维基百科确实很好地涵盖了它:)

关于java - Telnet session 与 TCP session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20777385/

相关文章:

java - 无法将 SessionVariable 传递给其他流 Mule

java - 设置目录的读取权限

java - 需要一些关于这个通用 Java 的帮助

c# - Response.Redirect(URL, false) - 重定向后事件管理

linux - 如何在 zmq(本地套接字)中获取调用者 pid

python - 在 Socket Python 上发送图片

php - 如果自动加载,则阻止 codeigniter session 库发送 set-cookie header 参数

java - 代码不在 Debug模式下执行,需要源代码

java - 如何在 Java 中构造像 new String ('A' , 30) 这样的字符串

android - 从 C 服务器发送结构到 java (android) 客户端