Java socket programming (I) socket transmission mode

Socket transport mode sockets have two main operation modes: connection oriented and connectionless Connection - oriented sockets operate like a telephone. They must establish a connection and call one person All things arrive in the same order as they depart Connectionless sockets operation is like a mail delivery. There is no guarantee. Multiple mails may arrive in a different order from their departure Which mode to use is determined by the needs of the mail application If reliability is more important, it would be better to use connection - oriented operations For example, file servers need 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 data blocks intermittently If the data is lost, the server does not want to send it again Because when the data arrives, it may be out of date Ensuring the order and correctness of data requires additional memory consumption, which will reduce the response rate of the system Connectionless operations use datagram protocol A datagram is an independent unit that contains all the information about this delivery Think of it as an envelope. It has a destination address and what to send The socket in this mode does not need to connect to a destination socket, it just simply throws a datagram Connectionless operation is fast and efficient, but data security is poor Connection - oriented operations use the TCP protocol A socket in this mode must obtain a connection with the destination socket before sending data Once the connection is established, sockets can use a stream interface: Open - read - write - close All sent messages are received in the same order at the other end Connection oriented operations are less efficient than connectionless operations, but data security is higher Sun has always been a supporter of network construction, so it's not surprising to support sockets in Java In fact, Java reduces the difficulty of building a sockets program Each transport pattern is encapsulated in a different class Connection - oriented classes will be discussed first There are two main operation modes of sockets: connection - oriented and connectionless The connection - oriented sockets operation is like a telephone. Multiple messages may arrive in a different order from their departure Which mode to use is determined by the needs of the mail application If reliability is more important, Java reduces the difficulty of building a sockets program Each transport pattern is encapsulated in a different class Connection - oriented classes will be discussed first

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>