Java/android network summary

Source: Internet
Author: User

In network programming, only by understanding the nature of network programming can we better master the network.

The first is the definition of the network. In the end, the network is the information interaction across computers. It is very important to understand this point and understand the essence of the network. At the same time, we should understand that there are not many knowledge points in transmission. The key lies in the protocol and other things that determine the data format. That is to say, the Protocol is the top priority of network programming. Therefore, you must master the protocol. (Network protocols are also called protocols. They contain three elements: syntax, semantics, and time sequence. Protocols are classified into Ethernet, netbeui, IPX/SPX, TCP/IP, and TCP/IP protocols, which are currently the mainstream because of good scalability, stability, and security)

There are various protocols in the computer, and the complete abstract model of this Protocol training is the layer-7 mode of the OSI Mode, and the inter-layer relationship is from bottom to top, that is to say, the upper layer must pass through the lower layer, so sometimes it looks like the connection between the layer and the layer does not pass through the lower layer. At the same time, you should also pay attention to the role of each layer, and the number of different protocols may be different. For example, the TCP/IP protocol is a layer-4 protocol. Pay attention to the HTTP protocol in the TCP/IP protocol application layer, which is the top priority of network programming, because the application layer is responsible for inter-program interaction.

TCP/IP only supports layer-4 protocols, including the application layer, transmission layer, Interconnection layer, and network interface layer. The application layer is used for inter-program access. There are HTTP protocol (Hypertext Transfer Protocol) network communication rules that follow the request/response model. The transport layer is responsible for data transmission based on protocols such as TCP and UDP. The Network Interconnection layer has the IP protocol (Internet Protocol), which ensures that the data can be transmitted to the destination address (that is, it is determined that the data must arrive, otherwise it will be resold ). The Network Interface Layer manages the actual network media (Network cables and other devices ).

The HTTP protocol of TCP/IP is socket-based, and most network applications are point-to-point. The point is the server and client programs.

HTTP and other protocols used in the application layer are the most common protocols. We often say that they are the most concerned about the application layer protocol in programming, because other protocols, especially the lower-layer protocols, are rarely used, because many underlying things in programming do not need to be modified, but are encapsulated, such as the TCP protocol, IP protocol, etc. (but real experts should be familiar with it to customize their own underlying protocols or intrude into others' computers ). That is to say, in most cases, the application layer protocol is used for programming, but if you want to control the entire network system, you have to operate on all layers. The application layer has many protocols, such as HTTP, SMTP, and mime. (HTTP, UDP, and TCP are all transmission protocols extended for certain scenarios based on the socket concept.) (the default port of the browser in HTTP is 80 ,)

For network communication, use socket and various protocols based on socket extension, because it only involves the transmission of data and some commands (in the final analysis, data transmission ), however, computer science is developing. If we add all the functions to a computer, the requirements for the computer itself will become higher and higher, however, when science cannot enable a computer to implement a large number of functions, it is a good way to use the distributed service framework to distribute functions to other computers, which can reduce costs, integrate available resources, but at the same time provide a stable method to call each other's resources, so a distributed service framework is born, the biggest feature of this framework is that their computers can call other computer methods, which is equivalent to seeing a computer as a black box and a black box that provides a specific method, we don't need to worry about how the black box is implemented. Therefore, in addition to java.net and android.net, we also need to know how to call RPC and RMI through remote methods. Therefore, we also need to know how to use Java. RMI and other related packages.

RPC directly requests services on a remote computer through a network without understanding the protocols on the computer. It assumes that a protocol exists, that is, RPC spans the application layer and transmission layer. (RPC supports multiple languages and RMI only supports Java.) RPC does not support objects. Messages transmitted to RPC must be expressed in the external data language (XDR, XDR abstracts the differences between the bytecode class and the data type structure, and RPC can only pass the data structure represented by XDR. (RMI is an Object-Oriented Java RPC) (by the way, the byte order refers to the order in which bytes are stored. There are two types of Le little
Endian and be big endian, from left to right. The former is from small to big, and the latter is big to small. The latter is the most natural form and also the form of network storage .)

In fact, RPC is more embodied in an idea, the most common design form, that is, by implementing a specific network class like a policy mode, and then calling this network class method, in this way, the remote object is called by the remote party. So it can be said that this network class represents the program to be called and is operated.

JMS is a Java Message Service. It is a Java API that allows an application to create, accept, send, and read messages, but it is different from RMI, JMS asynchronously transmits an object from one JVM to another JVM, while RMI can only pass parameters and return values. Rmi itself is bound to its own JVM.

In the distributed service framework, the most basic problem is communication. There are many implementation technologies in the Java underlying field, and the technologies in the underlying field are encapsulated, first, master several basic technologies (the underlying Java communication technologies include RMI, EJB, JMS, ESB, Mina, borlap, and soap. The encapsulated tools include hession, axis, xfire, and httpinvolker. Need to master RMI, XML-RPC, BINARY-RPC, JMS ). Communication technology is implemented based on the transmission protocol and network I/O, the transmission protocol is TCP, HTTP, and the network I/O is NiO, but considering the ease of use of applications, various Languages provide some application layer protocols that are closer to the application, Java's most well-known remote communication protocols are: RMI, XML-RPC, BINARY-RPC, soap, JMS.

Simple Object Access Protocol for soap is a simple, lightweight, and XML-based protocol. The Simple Object Access Protocol is designed to exchange structured and solidified information on the Web. It is one of the three elements of WebService. Soap is used to transmit the information format (that is, the format of the data packet to be transmitted ).

NIO, bio, AIO, bio are the IO we usually use, such as inputstream, NiO is the meaning of New Io, together with the class used by AIO are the class above NiO used. For network transmission, if it matches the transmission protocol, there are four situations: TCP/IP + bio, TCP/IP + NiO, UDP/IP + bio, UDP/IP + NiO, this division should be said to be a kind of thinking, but in fact all classes are used. In fact, in terms of nature, they are still I/O, but the fields used are not the same, but they are only changes in classes. The key lies in UDP/IP, the Data Packet technology is used, so the class names used contain datax, TCP/IP generally does not have class name settings, at the same time, bio is generally the socket used, NiO uses the channel, and AIO uses the NIO class, but its class has an asynchronous, in general, these programming classes exist in Java. io, Java. among the NIO packages (Java. most NiO packages are in Java. NIO. in channels ).

The Objective C () method can operate commands, but the degree of freedom is not high. It cannot be said that it is a real remote method call.) RMI is an interface and has its own special package, on this basis, you can understand. RPC actually exists as a concept in most cases. Therefore, the names of related classes that use its ideas are added to RPC, which indicates that the design is guided by the RPC idea.

Network Programming of urlconnection and URL is ultimately based on the TCP protocol.

Network Programming actually uses the last two lines. One is network programming of urlconnection and URL, and the other is programming of socket and C/S.

In fact, the Network aspect is relatively simple compared with the Web page design. It is the programming of the above applications to realize the actually desired data transmission function.

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.