Java Socket programming (I) Socket Transmission Mode

Source: Internet
Author: User

 

 

Socket Transmission Mode

Sockets has two main operations: connection-oriented and connectionless. connection-oriented sockets operations are like a phone. They must establish a connection and a person call. the order of all things at arrival is the same as that at their departure. the connectionless sockets operation is like a mail delivery, with no guarantee. The order of arrival of multiple mails may be different from that of departure.

Which mode is used depends on the mail application. if reliability is more important, connection-oriented operations will be better. for example, the file server needs the correctness and orderliness of their data. if some data is lost, the system's validity will be lost. some servers, such as sending some data blocks intermittently. if the data is lost, the server does not want to resend it again. because when the data arrives, it may be out of date. to ensure data orderliness and correctness requires additional memory consumption for operations, and additional costs will reduce the system response rate.

Connectionless operations use the datagram protocol. A datagram is an independent unit that contains all the information about this delivery. think of it as an envelope with a destination address and content to be sent. in this mode, the socket does not need to connect to a destination socket, but simply outputs a datagram. connectionless operations are fast and efficient, but data security is poor.

Connection-oriented operations use the TCP protocol. in this mode, the socket must connect to the destination socket before sending data. once the connection is established, sockets can use a stream interface: Open-read-write-close. all sent messages will be received at the other end in the same order. connection-oriented operations are more efficient than non-connection operations, but data security is higher.

SUN has always been a supporter of network construction, so it is not surprising to support sockets in Java. in fact, Java reduces the difficulty of creating a sockets program. each transmission mode is encapsulated in different classes. connection-oriented classes will be discussed first.

Sockets has two main operations: connection-oriented and connectionless. connection-oriented sockets operations are like a phone. They must establish a connection and a person call. the order of all things at arrival is the same as that at their departure. the connectionless sockets operation is like a mail delivery, with no guarantee. The order of arrival of multiple mails may be different from that of departure.

Which mode is used depends on the mail application. if reliability is more important, connection-oriented operations will be better. for example, the file server needs the correctness and orderliness of their data. if some data is lost, the system's validity will be lost. some servers, such as sending some data blocks intermittently. if the data is lost, the server does not want to resend it again. because when the data arrives, it may be out of date. to ensure data orderliness and correctness requires additional memory consumption for operations, and additional costs will reduce the system response rate.

Connectionless operations use the datagram protocol. A datagram is an independent unit that contains all the information about this delivery. think of it as an envelope with a destination address and content to be sent. in this mode, the socket does not need to connect to a destination socket, but simply outputs a datagram. connectionless operations are fast and efficient, but data security is poor.

Connection-oriented operations use the TCP protocol. in this mode, the socket must connect to the destination socket before sending data. once the connection is established, sockets can use a stream interface: Open-read-write-close. all sent messages will be received at the other end in the same order. connection-oriented operations are more efficient than non-connection operations, but data security is higher.

SUN has always been a supporter of network construction, so it is not surprising to support sockets in Java. in fact, Java reduces the difficulty of creating a sockets program. each transmission mode is encapsulated in different classes. connection-oriented classes will be discussed first.

 

 

Related Article

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.