Distributed Computing (ii)--socket communication with HTTP server (1)

Source: Internet
Author: User
Tags rfc string format time and date file transfer protocol

1. list the name of the Network layer Seven protocol, explaining the function of the Transport layer (TCP/UDP) and the Network layer (IP) separately.

Application layer, presentation layer, session layer, Transport layer, network layer, data link layer, physical layer.

TCP/UDP: Provides an end-to-end service between host application processes.

IP: Enables transparent data transfer between two end systems, including addressing and routing, connection creation, retention, and termination.

What floor is 2.Socket on? Explains the role of the port number.

Transport layer.

ports provide a unified, unique way to identify the hosts, processes, and connections that participate in the communication.

3.TCP is also called a streaming Socket. Is there a connection to the streaming file?

Exist.

A streaming file is a collection of multimedia files that can be streamed over a network , and is a collection of ordered characters whose length is the number of characters that the file contains. The implementation of the streaming transmission needs the appropriate transport protocol, in the implementation of the streaming transmission, the general use of HTTP/TCP to transmit control information.

4. Read Figure 2-8, connect the socket to the same data socket? Why do we usually only customize the 4-digit port number when programming?

Different.

Connection A socket is a connection request that is designed to receive a client program.

Data A socket is a virtual connection channel with a client program for data transfer, and so on.

most The TCP/IP implementation assigns the port number between 1024~5000 to the ephemeral port. Port numbers greater than 5000 are reserved for other servers.

5. The factory method is mentioned in the documentation. Please use UML to draw out InetAddress, inet4address and inet3address relations.

6. Against figure 2.9, write down the key code for each step.

The server listens and waits for a connection:

ServerSocket listensocket = new ServerSocket (Integer.parseint (args[0]));

Socket socket = listensocket.accept ();

Client Request Connection:

Socket socket = new socket (Args[0], Integer.parseint (args[1]));

Open the input and output stream:

PrintWriter out = new PrintWriter (Socket.getoutputstream (), true);

BufferedReader in = new BufferedReader (New InputStreamReader

(Socket.getinputstream ()));

To close the connection:

Out.close ();

In.close ();

Socket.close ();

7. (! Modify Mtechoserver to manage the client connected service thread with the Java list<> object. When the connection is broken, the service thread simply hangs. When a new connection is requested, if there is a pending service thread, the service is directly for the new connection.

8. Write The full name of the RFC and the IETF. The RFC number of the HTTP1.1 agreement and the URL of the full text are given.

Rfc:requests for Comments,internet standard draft definition organization

Ietf:internet Engineering Task Group,internet Engineering Tasks Group

RFC number of the HTTP1.1 protocol: 2616

Full text site:http://www.ietf.org/rfc/rfc2616.txt

9. Read the daytime protocol development and simply explain the meaning of figure 2-11. Its role in the program reading.

Mystreamsocket inherits the socket and adds the Setstreams () method to create the data input stream and the output stream.

The SendMessage () method is used to send data; the ReceiveMessage () method is used to receive data.

The DaytimeServer2 uses Mystreamsocket and ServerSocket.

DaytimeClient2 used the DaytimeClientHelper2.

DaytimeClientHelper2 used the Mystreamsocket.

The Xxhelper class is often written in the program, describe the role that the DaytimeClientHelper2 class plays in the DAYTIMETCP program.

The primary role of the DaytimeClientHelper2 class is to manage DaytimeClient2 class-to-server communication, including connecting to the server through the Mystreamsocket class, and the Gettimestamp () method sends a request to the service side and receives The response message, the ReceiveMessage () method receives the service-side response message, and so on.

One. run Java version httpserver. Design 3 Curl instructions, test the program's three output responses, give the console input and output.

Run Httpserver

Use the command curl localhost

Curl–v localhost, showing the communication process

Save Web page source code using curl–o [filename] [url]

Individual Learning Summary

through this experiment, the preliminary master The concept of the Socket API and the basic concept of the network protocol. the use of streaming sockets ,TCP,UDP protocols have a preliminary understanding, and HTTP protocol and through the sample program simple practice of using a streaming Socket to establish a TCP Connection, to build a basic c/S network framework, Build multi-threaded servers, and The development of daytime protocols.

Socket API

a socket is a collection of physical network addresses and logical port numbers that can be transferred to another location with a socket that has the same definition . Since the socket is identified by the machine address and port number, each socket is uniquely identified in this way on a particular computer network. This allows the application to be uniquely positioned. There are two types of sockets: One is a streaming socket,it provides a logical connection between processes and supports reliable data exchange , and the other is the packet socket, which is non-connected and unreliable

Data Report Socket

A streaming file is a collection of multimedia files that can be streamed over a network , and is a collection of ordered characters whose length is the number of characters that the file contains.

Flow Type Socket

The implementation of streaming transmission needs the appropriate transport protocol, in the implementation of the streaming transmission, the general use of HTTP/TCP to transmit control information.

Application Layer Protocol Development

Daytime Protocol Development

Date Query Protocol ( Daytime Protocol) is a time-transfer protocol that is widely used by small computers running MS-DOS and similar operating systems, which do not specify a fixed transmission format and are only required to follow the ASCII Standard send data. Its function is to return the current time and date, formatted as a string format. This protocol is small enough to allow beginners to understand the protocol content and development process

FTP Protocol Development

File Transfer Protocol FTP(file Transfer Protocol) is a software standard for transferring computer files between two computers with different operating systems, working at the application layer. the FTP service typically runs on a two-and-a-half port. Port is used to transfer traffic between client and server, and Port is used for transport control flow. The control flow is idle when the data is transmitted through the data stream.

HTTP Protocol Development

Hypertext Transfer ProtocolHTTP(Hypertext Transfer Protocol) is dedicated to transmittingHTMLthe protocol for the document,1996released in the yearRFC 1945and the1999released in the yearRFC 2616each defines thehttp/1.0and thehttp/1.1. HTTPThe protocol adopts a typical "request-reply" Communication model: After the client program establishes a connection with the service program, it sends a service request to the service program, and the service program obtains the correspondingHTMLThe document is sent back to the client as a reply, and the connection is finally closed

Distributed Computing (ii)--socket communication with HTTP server (1)

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.