csc123_W7_2.pdf
Document Details
Uploaded by WarmerMemphis
Tags
Full Transcript
CSC123 (INTRO TO PROGRAMMING II) Usman Aslam | Computer Science CLIENT PROCESSES A client process seeks the service of a server process. The client process: Opens a network connection to the server Sends request Receives response Closes connection when done java.net.Socket class represents a client...
CSC123 (INTRO TO PROGRAMMING II) Usman Aslam | Computer Science CLIENT PROCESSES A client process seeks the service of a server process. The client process: Opens a network connection to the server Sends request Receives response Closes connection when done java.net.Socket class represents a client socket SERVER PROCESS A Server process provides a service to clients. It is always “listening” on a pre-defined network port waiting for client connections. The server process: Attaches itself to a specific network port and starts listening Accepts client connection and establishes a two-way communication channel Receives client requests and processes it Sends the response to the client Closes connection when done (Connection closure can be initiated by the client or the server, depending on the protocol) java.net.ServerSocket class represents a server socket JAVA.NET PACKAGE The java.net package provides a range of classes to facilitate various types of network interactions and protocols There are two fundamental classes java.net.Socket: Represents a network client. Provides methods to open network connection to a server process and carry out two-way communication java.net.ServerSocket: Represents a server process. Binds to a local port, listens for client connections, and facilitates two-way communication with the client HTTP PROTOCOL Hypertext Transfer Protocol (HTTP) is the most widely used protocol. It is used to serve web pages. The client (e.g. a web browser) opens a network connection to the server on network port 80 (plain text) or 443 (encrypted) The client then sends an HTTP request using a specific syntax and waits for the response The server receives the request, processes it, and returns the response in a specific syntax back to the client HTTP REQUEST HTTP Request consists of three parts: Request keyword: Specifies the nature of the request. Resource: The actual resource you are looking for e.g. a web page, a file, an image, a video, etc. Header: Additional information e.g. browser type, version, cookies, etc. that the server might find useful. These vary based on your needs. There is also an optional HTTP version number that can be added to the request HTTP REQUEST Request keyword: Specifies the nature of the request. For this class, two keywords are important: GET: This specifies that you are asking the server to return you the resource you are looking for. It could be a file, a web page, an image, a video, etc. HEAD: You are asking for the server to only return HTTP headers back to you and nothing else. HTTP REQUEST Resource: The actual resource you are looking for e.g. a web page, a file, an image, a video, etc. Examples: / - you are asking for the home page /somedirectory/somefile.html - you are asking for a specific file to be returned HTTP REQUEST Header: Additional information e.g. browser type, version, cookies, etc. that the server might find useful. These vary based on your needs. Each header is defined on a new line: host:www.google.com Cookie: user-agent: HTTP RESPONSE HTTP Response has three parts: Response Code: Has a number and a string and indicates whether your request was successful or otherwise Header: Similar to the request header, it contains additional information sent by the customer Body: Contains the actual response COMMON HTTP RESPONSE CODES 200 – OK: Your request was successful and a response has been provided 404 – Not Found: The resource you are looking for was not found 400 – Bad Request: your request did not make sense to the server 301 – Moved Permanently: The resource you are looking for has temporarily moved to another location 302 – Moved Temporarily: The resource you are looking for has permanently moved to another location EXERCISE Demonstrate HTTP protocol using Telnet Demonstrate SMTP protocol using Telnet ADDITIONAL RESOURCES Please consult these resources before the next class so that you are comfortable with the basics of network communication. https://www.youtube.com/watch?v=eesqK59rhGA (HTTP) https://www.youtube.com/watch?v=iYM2zFP3Zn0 (HTTP) https://www.youtube.com/watch?v=PJo5yOtu7o8 (SMTP INTRO) https://www.youtube.com/watch?v=lfYtz3uRPYc (SMTP commands)