Article Source: ASPCN Author: Sun Wen
Socket transfer Mode
Sockets has two main modes of operation: connection-oriented and connectionless. Connection-oriented sockets operations are like a phone call, They have to establish a connection and a call to one person. All things arrive in the same order as they set out. A connectionless sockets operation is like a mail delivery, and there is no guarantee that multiple messages may arrive in the same order as they were when they started.
Which model to use is the need of the mail application. If reliability is more important, it's better to use a connection-oriented operation. For example, file servers require the correctness and order of their data. If some data is lost, the effectiveness of the system will be lost. Some servers, For example, send some chunks of data intermittently. If the data is lost, the server does not want to send it again. Because when the data arrives, it may be obsolete. Ensuring that the data is ordered and correct requires additional operational memory consumption, and additional costs will reduce the system's response rate.
Connectionless operations use datagram protocols. A datagram is a self-contained unit that contains all of the information for this post. Think of it as an envelope, it has the destination address and the content to send. The socket in this mode does not need to connect a socket for a purpose, It simply throws out the datagram. Connectionless operations are fast and efficient, but data security is poor.
Connection-oriented operations use the TCP protocol. A socket in this mode must obtain a connection to the socket of the destination before sending the data. Once the connection is established, sockets can use a stream interface: Open-read-write-close. All messages sent are received in the same order at the other end. Connection-oriented operations are less efficient than connectionless operations, but the data is more secure.
Sun has always been a supporter of network building, so it is not surprising to support sockets in Java. In fact, Java reduces the difficulty of building a sockets program. Each transport mode is encapsulated into a different class. The class for the connection will be discussed first.
Sockets has two main modes of operation: connection-oriented and connectionless. Connection-oriented sockets operations are like a phone call, They have to establish a connection and a call to one person. All things arrive in the same order as they set out. A connectionless sockets operation is like a mail delivery, and there is no guarantee that multiple messages may arrive in the same order as they were when they started.
Which model to use is the need of the mail application. If reliability is more important, it's better to use a connection-oriented operation. For example, file servers require the correctness and order of their data. If some data is lost, the effectiveness of the system will be lost. Some servers, For example, send some chunks of data intermittently. If the data is lost, the server does not want to send it again. Because when the data arrives, it may be obsolete. Ensuring that the data is ordered and correct requires additional operational memory consumption, and additional costs will reduce the system's response rate.
Connectionless operations use datagram protocols. A datagram is a self-contained unit that contains all of the information for this post. Think of it as an envelope, it has the destination address and the content to send. The socket in this mode does not need to connect a socket for a purpose, It simply throws out the datagram. Connectionless operations are fast and efficient, but data security is poor.
Connection-oriented operations use the TCP protocol. A socket in this mode must obtain a connection to the socket of the destination before sending the data. Once the connection is established, sockets can use a stream interface: Open-read-write-close. All messages sent are received in the same order at the other end. Connection-oriented operations are less efficient than connectionless operations, but the data is more secure.
Sun has always been a supporter of network building, so it is not surprising to support sockets in Java. In fact, Java reduces the difficulty of building a sockets program. Each transport mode is encapsulated into a different class. The class for the connection will be discussed first.