Java Socket
Socket (socket) provides a mechanism for communication between two computers, and before jamesgosling notices the Java language, sockets are already well known. The language only allows you to use sockets effectively without having to understand the details of the underlying operating system.
1 Client/server model
In the restaurant, all kinds of exotic food on the menu are reflected in your eyes, so you ask for a pizza. After a few minutes, you chew on the hot pizza of melted cheese and other ingredients you like. You don't know, you don't want to know: The waiter got pizza from there, what he added in the process, and how the ingredients were obtained.
The entities included in the previous example are: Delicious pizza, waiter who accepts your order, pizza kitchen, and you, of course. You are a pizza customer or customer. The process of making pizza is encapsulated for you. Your request is processed in the kitchen, and the pizza is finished and sent to you by the waiter.
What you are looking at is a client/server model. The client sends a request or command to the server. The server handles the client's request. Communication between client and server is an important part of the client/server model, usually over the network.
The client/server model is an application development framework designed to separate the presentation of data from its internal processing and storage. The client requests the service, and the server serves these requests. Requests are passed from the client to the server over the network. The processing performed by the server is hidden from the client. A server can serve multiple clients.
Multiple Client Access servers
Servers and clients are not necessarily hardware components. They can be work, the same machine, or a program on a different machine. 、
Consider a data entry program in an airline ticketing system: Data----Passenger name, flight number, flight date, destination, etc. can be entered into the front-end----client application. Once the data is entered, the client sends the data to the back-end----server side. The server processes the data and saves the data in the database. The importance of the client/server model is that all data is stored in the same location. The client accesses the same data source from different places, and the server applies the same validation rules to all the input data.
The World Wide Web provides a good example of why the presentation of data is separated from its storage and processing. On the Web, you don't have to control the platforms and software that end users use to access your data. You may consider writing applications that apply to each potential target platform.
The server portion of the client/server application manages resources shared by multiple users accessing the server through multiple clients. The best example of a ' server part ' of the client/server program is a Web server that passes HTML pages to different Web users over the Internet.
The most basic feature of the Java programming language is the portability of code for programs created in Java. Because of code portability that is not available in other languages, Java allows a user to write an application once, to publish it on any client system, and to have the client system interpret the program. This means that you can make it run on any platform by simply writing the code once.
2 protocol
When you talk to friends, you follow some implied rules (or agreements). For example: You two cannot start talking at the same time, or you can talk continuously without interruption. If you do this, no one can understand what the other person is saying. When you talk, your friends listen and vice versa. You can talk to each other in a language and speed that you both understand.
When communicating between computers, you also need to follow certain rules. Data is sent from one machine to another in the form of a package. These rules manage data packaging, transmission speed, and re-data restoration to their original form. These rules are called network protocols. A network protocol is a series of rules and conventions followed by a system that communicates over a network. Networking software usually implements multi-layer protocols with high levels of low-level. Examples of network protocols are: TCP/IP, UDP, AppleTalk, and NetBEUI.
Java provides a rich, network-enabled class library that makes it easy for applications to access network resources. Java provides two types of communication tools. These are: Messages using User Message Protocol (UDP) and sockets (sockets) using Transmission Control Protocol/Internet Protocols (TCP/IP).
A datagram packet is a byte array that is routed from one program (the sender) to another (the receiving program). Because the datagram adheres to UDP, it is not guaranteed that the packets sent must arrive at the destination. Datagrams are not trustworthy. Therefore, it is only used when a small amount of data is transferred, and the distance between the sender and the recipient is small, if the network traffic is high, or if the receiving program is processing multiple requests from other programs, there is a chance of losing the datagram packet.
Sockets sockets are communicated using TCP. Compared with other models, the socket model has the advantage of not being affected by where the customer requests come from. The server serves its request as long as the client follows the TCP/IP protocol. This means that a client can be any type of computer. Clients are no longer limited to UNIX, Windows, DOS, or Macintosh platforms, so all computers that follow the TCP/IP protocol on the web can communicate with each other through sockets.