Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 18 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
18
Dung lượng
2,03 MB
Nội dung
VIETNAM - KOREA UNIVERSITY OF INFORMATION AND COMMUNICATION TECHNOLOGY Faculty Of Computer Science REPORT BUILDING A WEB SERVER WITH JAVA SOCKETS Students: LÊ PHÚ QUỐC Class: 20GIT Instructor: Assoc Prof PhD HUỲNH CÔNG PHÁP Danang, January 2023 VIETNAM - KOREA UNIVERSITY OF INFORMATION AND COMMUNICATION TECHNOLOGY Computer Science Department REPORT BUILDING A WEB SERVER WITH JAVA SOCKETS Students: LÊ PHÚ QUỐC Class: 20GIT Instructor: Assoc Prof PhD HUỲNH CÔNG PHÁP Danang, January 2022 THANK YOU First of all, we would like to thank the lecturers of the Computer Department of Vietnam - Korea University of Information and Communication Technology and the instructor Assoc Prof Ph.D Huynh Cong Phap for guiding and instructing us I have successfully completed the report In the process of making the report, errors cannot be avoided We look forward to receiving your comments and corrections to make our report more complete, as well as to learn more experiences to better complete the upcoming report Students Lê Phú Quốc CONTENTS THANK YOU .3 CONTENTS .4 LIST OF ACRONYMS .6 PREAMBLE Introduction: Target: Report layout: Chapter OVERVIEW Socket HTTP Protocols .9 End of chapter 1: 11 Chapter IMPLEMENTATION 12 Program structure 12 Implementation 13 Result .15 End of chapter 17 Chapter CONCLUSIONS AND DEVELOPMENT ORIENTATIONS .18 Conclusions 18 1.1 Achievements 18 1.2 Limitations: 18 Development: 18 REFERENCES 19 LIST OF FIGUR Figure Web Server Overview 11 Figure Downloading files Web Server and resource.zip 12 Figure Extracting resource.zip 12 Figure Executing WebServer.jar 13 Figure Browsing to folder which contains files of resource.zip 13 Figure Picture page 14 Figure Response Header 15 Figure Profile page and web server GUI .16 Y PREAMBLE Introduction: A simple web server system is a software program that receives and responds to requests from clients over the internet It consists of one or more physical or virtual machines running a web server software program, which is responsible for processing incoming requests and sending responses back to the client The web server listens on a specific port for incoming HTTP requests, and when it receives a request, it parses the request to determine the requested resource (such as a web page or image) and sends back an appropriate response The system typically also includes a database for storing and retrieving data related to the website, as well as other services such as email servers, caching servers, load balancers, and security components A simple web server system is a critical component of any website or web application, as it serves as the foundation for delivering content and services to users over the internet Target: - Learn and master the necessary languages to apply to the design Learn, read sources of documents and reference information Research the actual situation, through books, or the internet Understanding web architecture - Learn TCP/IP, HTTP network protocols Network programming support libraries Report layout: After the Introduction, the report is presented in three chapters, specifically as follows: - Chapter Overview In this chapter, the report presents the concepts and characteristics of the components used to implement the project - Chapter Implementation The content presents the results of the process of implementing and developing the topic - Chapter Conclusions and development orientations The content presents achievements and limits and directions for development Finally, there are references and appendices related to the topic Chapter OVERVIEW Socket A socket is a software endpoint that enables communication between different applications or processes over a network The TCP/IP protocol is a set of networking protocols that is used to establish a connection between different devices over the internet Together, sockets and TCP/IP provide a foundation for network communication and data transfer When two devices communicate using sockets and the TCP/IP protocol, they establish a reliable and ordered stream of data between them This is done by breaking data into small packets that are transmitted over the internet, and then reassembling those packets at the destination device TCP/IP also provides a mechanism for error checking and correction, ensuring that the data that is received is identical to the data that was sent Sockets and TCP/IP are used in many different types of applications, from web browsers to email clients to file transfer programs They are used to transfer a wide variety of data, including text, images, audio, and video One important concept to understand when working with sockets and TCP/IP is the difference between a client and a server In this context, a client is a device that initiates a connection, while a server is a device that listens for incoming connections When a client initiates a connection, it sends a request to the server, which responds with a message This back-and-forth communication is the basis for many network applications, such as web browsing, email, and instant messaging In summary, sockets and TCP/IP are essential components of network communication, allowing different devices to exchange data in a reliable and ordered manner By understanding how these technologies work, you can develop more effective and efficient network applications that can take advantage of the power and reach of the internet HTTP Protocols HTTP (Hypertext Transfer Protocol) is a protocol for transferring data over the Internet HTTP is used to transmit web pages, images, audio, video, and other documents between devices connected to the Internet HTTP works on the Client-Server model When a client requests a resource from the server, the client sends a request to the server The server will return a response (response) with the resource requested by the client Requests and responses are sent between the client and the server as packets on the network Every HTTP request and response has a standard format An HTTP request consists of the following parts: - Request line: This is the first line of the request, containing information about the method (method), path (path) and version of HTTP that the client is using - Header: Additional information fields of the request, like User-Agent, AcceptEncoding, Content-Type, etc These headers provide the server with information about the client and the client's request - Body: The body of the request, which can be data sent to the server (like when POSTing data) or nothing (like when GET resources) The HTTP response consists of the following parts: - Status line: This is the first line of the response, containing information about the HTTP version, the status code, and a message describing that status code - Header: Additional information fields of the response, like Server, ContentType, Content-Length, etc These headers provide the client with information about the server's response - Body: The body of the response, containing the requested resource (such as when GET resources) or the error message (such as when an error occurs during request processing) HTTP also supports many methods (methods) to make different requests, like GET, POST, PUT, DELETE, etc Each method will have different purposes and uses, depending on the type of request the client wants to make HTTP is a very important protocol in the transmission of data on the Internet, especially in accessing websites and web applications It is a widely used standard protocol and is supported by most web browsers, web servers, and devices connected to the Internet The status code is an important part of HTTP, used to provide information about the result of a request Status codes are sent in the status line of the response and are categorized into main categories: - 1xx (Informational): Information, being processed - 2xx (Successful): Successful, the request was processed successfully - 3xx (Redirection): Redirect, request is redirected to another address - 4xx (Client Error): Client error, request is invalid or cannot be processed - 5xx (Server Error): Server error, server cannot handle client request HTTP headers are also important, as they provide additional information about the request and response Some important HTTP headers include: - User-Agent: Information about the browser or application sending the request - Content-Type: The data type of the content sent to the server or returned to the client - Content-Length: The length of the content sent to the server or returned to the client - Cookie: Information about the client's session on the server In an overview, HTTP is a very important protocol for the transmission of data on the Internet, especially in accessing websites and web applications Understanding HTTP will help you understand how websites work, which in turn can optimize performance and improve user experience End of chapter 1: Understanding the knowledge, components and technologies used to implement the project is the basis for the next phase of the project - implementation, which will be presented in the next chapter 10 Chapter IMPLEMENTATION Program structure Figure Web Server Overview Figure illustrates the high-level structure of my Web Server, with class and interface: - MainFrame: The main class, MainFrame is response for starting and stopping HttpServer This is also graphics user interface - HttpServer: is responsible listening on port which is configured by MainFrame (or 443, default ssl port) and spawaning an instance of SocketHandler for each client connection Its start method enters an infinite loop, spawning a new thread for each accepted connection and handing the new socket off to a new SocketHandler and then awaiting a new client connection - SocketHandler: in turn, is responseble for implementing the bulk of the HTTP protocol itself Its goal is to create a Request object, fill it in with the parse method, path, version and request headers, create a Response object and hand 11 - - that off to the associated Handler to actually fill in and respond to the client Most of the actual parsing of the HTTP request is handed off to the Request object itself Request: Parse the request of client: get method, path, url, header, parameter, query parameter Response: is a relatively passive class; it respond with the text HTTP/1.1 STATUS MESSAGE, a variable-length lisst of headers in the from NAME: VALUE, a blank line, and then the response body The Handler should set a response code, invoke addHandler once for each response header it plans to return, add a body and then invoke send to complete the response Handler: is an interface Implementation Step 1: Download files WebServer.jar and resource.zip Figure Downloading files Web Server and resource.zip Step 2: Extract file resource.zip Figure Extracting resource.zip 12 Step 3: Execute file WebServer.jar Figure Executing WebServer.jar Step 4: Browse to folder which contains files and folder of resource.zip Figure Browsing to folder which contains files of resource.zip Step 5: Start server 13 Result Figure Picture page 14 Figure Response Header 15 Figure Profile page and web server GUI End of chapter After completing the topic, the group will evaluate the results achieved and consult with the lecturers for updates and future development directions 16 Chapter CONCLUSIONS AND DEVELOPMENT ORIENTATIONS Conclusions 1.1 Achievements - Learn and master the necessary languages to apply to the design Learn, read sources of documents and reference information Research the actual situation, through books, or the internet Understanding web architecture - Learn TCP/IP, HTTP network protocols Network programming support libraries 1.2 Limitations: Besides the achievements, the web server still have some limitations: - Http methods are not fully supported yet Development: - Programming a more complete web server 17 REFERENCES 18