7.6.1 Socket Learning Network Basics Preparation
Category Android Basic Tutorial
Introduction to This Section:
>
To cater to beginners who have not studied Java Sockets, or to clarify the concepts related to network protocols involved in Android development, after all, during an interview, if the interviewer asks, "Tell me how many layers are there in the network protocol? Where is the IP protocol located? What is a Socket? What are the different types? What are the differences between TCP and UDP protocols... Well, this... So, it is still very necessary to learn the theoretical concepts of this section! So, without further ado, let's start the content of this section~
1. A Brief Analysis of the OSI Seven-Layer Network Model
>
Of course, we are not professional network engineers, just knowing what layers there are and what they are roughly used for is enough!
OSI Seven-Layer Network Model (from bottom to top) :
>
Physical Layer (Physical): Provides transmission media and interconnection devices for data communication between devices, providing a reliable environment for data transmission. It can be understood as the physical media part of network transmission, such as network cards, network cables, hubs, repeaters, modems, etc.! At this layer, data has not been organized, only treated as raw bit streams or electrical voltages, and the unit of this layer is: bit - bit
Data Link Layer (Datalink): Can be understood as a data channel, the main function is how to transmit data reliably on unreliable physical lines, the role of this layer includes: physical address search, data framing, flow control, data error checking and retransmission, etc.! In addition, this data link refers to : The physical layer should provide the transmission media and its connection for data communication between terminal devices. The media is long-term, and the connection has a lifespan. During the connection lifespan, the sender and receiver can carry out unequal one or more data communications. Each communication has to go through the process of establishing communication contact and dismantling communication contact! This established data transmission relationship ~ The equipment at this layer includes: network cards, network bridges, network switches, and the unit of this layer is: frame
Network Layer (Network): The main function is to translate network addresses into corresponding physical addresses and decide how to route data from the sender to the receiver, the so-called routing and path finding: a terminal may need to communicate with multiple terminals, which leads to the problem of linking data between any two terminal devices! In simple terms: establishing network connections and providing services for the upper layer! The equipment at this layer includes: routing! The unit of this layer is: data packet, and the IP protocol is at this layer!
Transport Layer (Transport): Provides communication services to the upper application layer, the highest layer of the communication part, and also the lowest layer in user functions. It receives session layer data, divides the data if necessary, and hands these data to the network layer, and ensures that these data segments are effectively delivered to the other end! So the unit of this layer is: data segment; and there are two very important protocols in this layer: TCP Transmission Control Protocol and UDP User Datagram Protocol, which are also the core parts of this chapter!
Session Layer (Session): Responsible for establishing, maintaining, and terminating communication between two nodes in the network. Establishing a communication link, keeping the communication link open during the session, synchronizing the dialogue between the two nodes, deciding whether the communication is interrupted and where to resend when the communication is interrupted, that is, the establishment and management of sessions between users on different machines!
Presentation Layer (Presentation): Interprets commands and data from the application layer, gives corresponding meanings to various syntaxes, and transmits them to the session layer in a certain format. Its main function is to "deal with the representation issues of user information, such as encoding, data format conversion, encryption and decryption, compression and decompression, etc."
Application Layer (Application): The top layer of the OSI reference model, providing network services for user applications. It is based on the work of the other six layers, responsible for completing the connection between network applications and network operating systems, establishing and ending the connection between users, and completing various network services and application requirements for supervision, management, and services. In addition, this layer is also responsible for coordinating the work between various applications. The services and protocols provided by the application layer to users include: file services, directory services, file transfer services (FTP), remote login services (Telnet), email services (E-mail), printing services, security services, network management services, System.out.println("Hostname: " + address.getHostName()); System.out.println("IP Address: " + address.getHostAddress()); byte[] bytes = address.getAddress(); System.out.println("IP Address in byte array form: " + Arrays.toString(bytes)); System.out.println("Direct output of InetAddress object: " + address); } }
Summary of This Section:
>
This section is all about concepts, which might be quite challenging, right? However, it's okay if you don't understand everything. Just knowing what each layer of the seven-layer model is called, what it's generally used for, and the TCP three-way handshake and four-way handshake, that's enough! Of course, this is just to cope with interviews~ In actual development, who would be concerned about this... Just use Socket directly, right? Well, next section we will start learning about Socket communication in Android. Thanks~
-1.0 Android Basic Tutorial Introduction
-1.0.1 Latest Android Basic Tutorial Table of Contents for 2015
-1.1 Background and System Architecture Analysis
-1.2 Development Environment Setup
-1.2.1 Developing Android APPs with Eclipse + ADT + SDK
-1.2.2 Developing Android APPs with Android Studio
-1.3 Solving SDK Update Issues
-1.4 Genymotion Emulator Installation
-1.5.1 Git Tutorial on Basic Operations of Local Repositories
-1.5.2 Git: Using GitHub to Set Up a Remote Repository
-1.6 How to Play with 9 (Nine Sister) Images
-1.7 Interface Prototype Design
-1.8 Project Related Analysis (Various Files, Resource Access)
-1.9 Android App Signing and Packaging
-1.11 Decompiling APK to Retrieve Code & Resources
-2.1 The Concept of View and ViewGroup
-2.2.1 LinearLayout (Linear Layout)
-2.2.2 RelativeLayout (Relative Layout)
-2.2.3 TableLayout (Table Layout)
-2.2.4 FrameLayout (Frame Layout)
-2.2.5 GridLayout (Grid Layout)
-2.2.6 AbsoluteLayout (Absolute Layout)
-2.3.1 TextView (Text Box) Detailed Explanation
-2.3.2 EditText (Input Box) Detailed Explanation
-2.3.3 Button (Button) and ImageButton (Image Button)
-2.3.5 RadioButton (Radio Button) & Checkbox (Checkbox)
-2.3.6 ToggleButton (Toggle Button) and Switch (Switch)
-2.3.7 ProgressBar (Progress Bar)
-2.3.9 RatingBar (Star Rating Bar)
-2.4.1 ScrollView (Scroll View)
-2.4.2 Date & Time Components (Part 1)
-2.4.3 Date & Time Components (Part 2)
-2.4.5 ListView Simple and Practical Use
-2.4.6 BaseAdapter Optimization
4.4.2 Further Exploration of ContentProvider - Document Provider
5.2.1 Detailed Explanation of Fragment Example - Implementation of Bottom Navigation Bar (Method 1)
5.2.2 Detailed Explanation of Fragment Example - Implementation of Bottom Navigation Bar (Method 2)
5.2.3 Detailed Explanation of Fragment Example - Implementation of Bottom Navigation Bar (Method 3)
6.2 Data Storage and Access - Saving User Preferences with SharedPreferences
6.3.1 Data Storage and Access - Introduction to SQLite Database
7.1.1 Things to Learn in Android Network Programming and Study of Http Protocol
7.6.1 Socket Study: Preparing the Network Basics
[8.3.4 Paint API - Detailed Explanation of Xfermode and PorterDuff (Part One)](android-
11.0 "The Latest 2015 Android Basic Tutorial" Concludes with Fireworks~
12.2 DrySister Girl Watching App (First Edition) - 2. Parsing Backend Data
12.4 DrySister Girl Watching App (First Edition) - 4. Adding Data Caching (Integrating SQLite)