JAVA Socket, socket

Source: Internet
Author: User

JAVA Socket, socket

Socket provides a mechanism for communication between two computers. Before James Gosling noticed the Java language, the socket was already famous. In order to facilitate the development of network applications, the Unix system has introduced a Socket, an operating system call for applications to access the communication protocol, which allows programmers to conveniently access the TCP/IP protocol, to develop various network applications. Later, Socket was introduced in Windows, and Socket programming model was introduced in Java.
Most programmers, whether or not they are coding in Java, do not want many low-level details about how applications on different computers communicate with each other. Programmers want to deal with more advanced abstractions that are easier to understand. Java programmers want to use the Java structures they are familiar with to interact with objects through intuitive interfaces. Sockets exist in both fields-we would rather avoid low-level details and abstract layers we prefer to process. The low-level details discussed in this tutorial will be limited to what is necessary for understanding abstract applications.

Sockets generally reside in the Session Layer of the OSI model. The Session Layer is sandwiched between the application-oriented layer and the real-time data communication layer. The Session Layer provides management and control services for data streams between two computers. As a part of this layer, the socket provides an abstraction to hide the complexity of getting the bit and byte from the wire. In other words, the socket allows an application to indicate that it wants to send some bytes to transmit data. The socket hides the details of this task.

 

Generally, sockets in Java have the following two forms:

  • TCP socketSocketClass implementation. We will discuss this class later)
  • UDP socketDatagramSocketClass implementation)

TCP and UDP play the same role, but the practice is different. Both receive transmission protocol data packets and send their contents to the presentation layer. TCP splits messages into data packets (Datagram, datagrams) And re-assemble them at the receiving end in the correct order. TCP also processes retransmission requests for lost data packets. With TCP, there are only a few things to worry about at the upper layer. UDP does not provide assembly and retransmission requests. It only transfers the information package forward. The layer at the upper layer must ensure that the message is complete and assembled in the correct order.

Generally, UDP imposes less performance overhead on your application, but only when the application does not suddenly exchange a large amount of data and does not have to assemble a large amount of data to complete a message. Otherwise, TCP is the simplest and most efficient choice. Most readers prefer TCP over UDP, so we will restrict the discussion to TCP-oriented classes in Java.

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.