Importance of the new line “\n” in Java networking

前端 未结 2 2034
醉话见心
醉话见心 2020-12-12 05:44

Well, I need a clarify of what is the importance of the \"\\n\" new line in the String variable here

import java.net.*;
import java.io.*;

         


        
相关标签:
2条回答
  • 2020-12-12 05:56

    The newline has no importance in Java networking.

    However it does have importance in many protocols, many of which are based on the 'Telnet Terminal' convention of \r\n as the line terminator. This certainly includes SMTP, FTP, HTTP, and Telnet itself.

    It also has importance for the BufferedReader.readLine() method. You will find hundreds of questions here about readLine() blocking forever, to which the answer is 'you are reading lines but you are not writing lines', i.e. just sending a string with no line terminator. This does not constitute a complete line, so readLine() doesn't return it.

    0 讨论(0)
  • 2020-12-12 06:16

    TCP port 43 is the WHOIS protocol explained here on Wikipedia: Whois

    If you see the article is says: Send a single "command line", ending with CRLF.
    That's why you need the newline in your code.

    0 讨论(0)
提交回复
热议问题