The disadvantage of PrintStream in network programming _ programming

Source: Internet
Author: User

First, the output of println () is platform-related. Depending on the machine running the code, the lines are sometimes separated by a newline, sometimes by a carriage return, or by a carriage return/newline pair. Writing to the console does not cause problems, but it is a catastrophe for network clients and servers that follow the exact protocol. Most network protocols, indicating that the carriage return/newline pair should be terminated. Using println () makes it easy to write a program that works with Windows, but does not work on UNIX and Macs. While many servers and clients can be "generous" to handle incorrect line terminators, there are occasional exceptions where a client running on Mac OS 9 uses println () to suspend the server and the client. In some programs, this may be fixed by using only print () and ignoring println ().

Second, all characters printed by PrintStream are converted to bytes using the platform's default character encoding. However, this encoding may not be what the server and client expect. You should use the PrintWriter class in cases where you need to write characters instead of writing bytes.

Third, PrintStream swallowed all the anomalies. is not sufficient for network connectivity.

Citation: Elliotte Rusty Harold Java Network programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.