Chapter17 Network Basic knowledge of network programming Client/Server Computing Model Network Address Class InetAddress Multi-Customer Service Sending and receiving objects Java高级程序设计(下) 1 Basic knowledge of network programming 1. Network Protocol and TCP/IP Network protocol: It specifies the addressing rules between computers, the resolution of data c onflicts, and how long data is transmitted and received in segments. TCP/IP: It is a very useful network protocol, which is followed by the Internet. Network applications: Programs running on different computers that have realized network interconnection.Data can be exchanged between them.Writing a network program requires first clarifying the netwo rk protocol it uses. 2. IP Address and Port (Port Number) IP: Used for the identification of computers on the Internet, which is represented by 32 bits (4 b ytes) and four segments in decimal numbers of 0-255 separated by dots, such as 172.25.13 8.49. Domain name: www.zzti.edu.cn Local loop address: 127.0.0.1 Port: Used to indicate which network program handed over the data for processing.Scope 0-65 535. 0-1023 has been used for well-known network services, such as 25 for e-mail server ports. For example: SQL server: 1433 mysql: 3036 Java高级程序设计(下) 2 Basic knowledge of network programming Ordinary network program use: 1024 to 65535 ports. TCP (Transmission Control Protocol): Connection-oriented com munication protocol that provides reliable error-free data tr ansmission between two computers.For example: telephon e UDP (User Data gram Protocol): Connectionless communicatio n protocol.Reliable data transmission is not guaranteed.For example, paging station sends information to users. The basic formats of TCP and UDP data packets (data frames): 协议类型 源 IP 目标 源端口 目标端口 Java高级程序设计(下) 帧序号 帧数据 3 Socket Socket: The network driver layer provides an interface and a m echanism for application programming. Mechanism: Socket is created in the application program. It establishes a rel ationship with the driver through a binding mechanism and tells itself the corresponding IP and Port. After that, the data sent to the socket by the application program is sent by the s ocket to the driver and sent to the network.After the comput er receives the data产生 related to IP+Port bound to Socket from 产生 Socket Socket the network, the driver gives it to Socket, and1the applicatio 1 extract the received data n program can from Socket. 应用程序 应用程序 2 3 数据给 Socket 2 Socket IP+Port 驱动程序 从 Socket 取数据 4 Socket IP+Port 4 Data transmission process Java高级程序设计(下) 驱动程序 Data receiving process 4 Client/Server Computing Model (Writing TCP Network Program) Write TCP network program: There are primary and secondary, one is called server program, and the oth er is called client program. The process of interaction between server and client: 1. The server program creates a ServerSocket and then calls the accept meth od to wait for the client to connect. 2. The client program creates a Socket and requests to establish a connectio n with the server. 3. The server receives the client's connection request and creates a new Soc ket to establish a dedicated connection with the user. 4. The two Sockets that have just established a connection talk on a separat e thread (created by a server program). 5. The server begins to wait for new connection requests. Server Socket: Similar to the 114 check-in counter. Socket: It's like a regular phone. Java高级程序设计(下) 5 ServerSocket Java.net.ServerSocket is used to create the socket of the server. Construction method: PublicServerSocket () throws IOException It is not bound to any port and cannot be used directly. It is necessary to continue calling t he bind () method. Public ServerSocket (int port) throws IOException If the specified port number is 0, the system will allocate a port that has not been used by other network programs.But as a server program, the port number must be specified beforehand so that other customers can connect according to this number, so it is not common to set it to 0.The default backlog is 50. Public Server Socket (int port, int backlog) throws IOException The backlog parameter specifies the number of waiting customers with which connection requests can be maintained when the server is busy. Public Server Socket (int port, int backlog, InetAddress bindAddr) throws IOException is s uitable for the case of multiple network cards and multiple IP on the computer. Accept (): a c

pptDoc Java Network

Professional Docs > Common > Other > Preview
13 Pages 0 Downloads 50 Views 3.0 Score
Tips: Current document can only be previewed at most page8,If the total number of pages in the document exceeds page 8,please download the document。
Uploaded by admin on 2019-10-16 00:29:36
Rate
You can enter 255 characters
What is my domain?( answer:www.45doc.com )
comments
  • No comments yet