Java network assignment and want to apologize for not having a starter code of this assignment. Step
Fantastic news! We've Found the answer you've been seeking!
Question:
Java network assignment and want to apologize for not having a starter code of this assignment.
Transcribed Image Text:
Step #1: Open a server socket. Start by writing a simple program that opens a ServerSocket on the port that was specified on the command line, accepts a connection, prints whatever it receives, and then exits. For now, ignore multithreading and everything else. Then run your program, using port 8000 (which is non-privileged and a common port for testing HTTP), and invoke the req test from the test suite. You should see your server print a GET request, including a few headers. If this isn't working, double-check that your program actually opened the correct port, e.g., using the netstat tool. Step #2: Send a dummy response. Next, try sending a simple HTTP response once the connection is open. You can do this by wrapping a Print Writer around the connection's OutputStream. Try sending HTTP/1.1 200 OK, followed by a CRLF, then Content-Type: text/plain, followed by two (!) CRLFs, and then any string. Close the connection. The req test should now pass, and you should be able to see the string the server is sending if you point any local browser on your machine to http://localhost:8000/. Step #3: Parsing the headers. Now, try to parse the request a bit more carefully. Since we will want to support binary uploads later, it is best to initially read the request as bytes, and to convert the headers to strings later on. Keep reading the data as it arrives, and look for the double CRLF (bytes 13, 10, 13, 10), which indicates the end of the headers. Once you see this, take the bytes you've received up to that point and convert them to strings - for instance, by wrapping the bytes in a ByteArrayInputStream, then in an InputStreamReader, and finally in a BufferedReader. When you read this line by line, the first line should be the request line, and the following lines should be the headers. Look for the relevant headers (in this assignment, only Content-Length) and parse them if present. (For now, let's assume that there is no message body, so the content length will be zero.) Then go back to reading the next request until the connection is closed, instead of just terminating your server. If you do this correctly, the persist test should now pass. Step #1: Open a server socket. Start by writing a simple program that opens a ServerSocket on the port that was specified on the command line, accepts a connection, prints whatever it receives, and then exits. For now, ignore multithreading and everything else. Then run your program, using port 8000 (which is non-privileged and a common port for testing HTTP), and invoke the req test from the test suite. You should see your server print a GET request, including a few headers. If this isn't working, double-check that your program actually opened the correct port, e.g., using the netstat tool. Step #2: Send a dummy response. Next, try sending a simple HTTP response once the connection is open. You can do this by wrapping a Print Writer around the connection's OutputStream. Try sending HTTP/1.1 200 OK, followed by a CRLF, then Content-Type: text/plain, followed by two (!) CRLFs, and then any string. Close the connection. The req test should now pass, and you should be able to see the string the server is sending if you point any local browser on your machine to http://localhost:8000/. Step #3: Parsing the headers. Now, try to parse the request a bit more carefully. Since we will want to support binary uploads later, it is best to initially read the request as bytes, and to convert the headers to strings later on. Keep reading the data as it arrives, and look for the double CRLF (bytes 13, 10, 13, 10), which indicates the end of the headers. Once you see this, take the bytes you've received up to that point and convert them to strings - for instance, by wrapping the bytes in a ByteArrayInputStream, then in an InputStreamReader, and finally in a BufferedReader. When you read this line by line, the first line should be the request line, and the following lines should be the headers. Look for the relevant headers (in this assignment, only Content-Length) and parse them if present. (For now, let's assume that there is no message body, so the content length will be zero.) Then go back to reading the next request until the connection is closed, instead of just terminating your server. If you do this correctly, the persist test should now pass. Step #1: Open a server socket. Start by writing a simple program that opens a ServerSocket on the port that was specified on the command line, accepts a connection, prints whatever it receives, and then exits. For now, ignore multithreading and everything else. Then run your program, using port 8000 (which is non-privileged and a common port for testing HTTP), and invoke the req test from the test suite. You should see your server print a GET request, including a few headers. If this isn't working, double-check that your program actually opened the correct port, e.g., using the netstat tool. Step #2: Send a dummy response. Next, try sending a simple HTTP response once the connection is open. You can do this by wrapping a Print Writer around the connection's OutputStream. Try sending HTTP/1.1 200 OK, followed by a CRLF, then Content-Type: text/plain, followed by two (!) CRLFs, and then any string. Close the connection. The req test should now pass, and you should be able to see the string the server is sending if you point any local browser on your machine to http://localhost:8000/. Step #3: Parsing the headers. Now, try to parse the request a bit more carefully. Since we will want to support binary uploads later, it is best to initially read the request as bytes, and to convert the headers to strings later on. Keep reading the data as it arrives, and look for the double CRLF (bytes 13, 10, 13, 10), which indicates the end of the headers. Once you see this, take the bytes you've received up to that point and convert them to strings - for instance, by wrapping the bytes in a ByteArrayInputStream, then in an InputStreamReader, and finally in a BufferedReader. When you read this line by line, the first line should be the request line, and the following lines should be the headers. Look for the relevant headers (in this assignment, only Content-Length) and parse them if present. (For now, let's assume that there is no message body, so the content length will be zero.) Then go back to reading the next request until the connection is closed, instead of just terminating your server. If you do this correctly, the persist test should now pass.
Expert Answer:
Answer rating: 100% (QA)
It seems you are working on a network programming assignment in Java to create a simple HTTP server Below is a basic outline of how you can implement ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Create an automated burglar alarm system that raises the gate of the lion's cage when the window and/or door are opened. Feel free to add items and/or use existing items. BEWARE OF LION
-
Skip to main content Lab 11: A Web Server The goal of this lab is to write a simple, but functional, web server that is capable of sending files to a web browser on request. The web server must...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
In a bygone day, airlines issued discount tickets to students who would be willing to fly on a particular day, with no notice, at a discounted price, one needed to show proof of being of student. The...
-
Use the result in Example 6 to find the orthogonal projection of x onto the line through the origin that makes an angle 0 with the positive x-axis. x = (- 1, 2); = 45
-
Remember that potential energy is stored in fields. Describe which two magnets you would use and how you would arrange them in order to have the most potential energy in the magnetic field
-
A DFD consists of the following four basic elements: data sources and destinations, data flows, transformation processes, and data stores. Each is represented on a DFD by a different symbol. a. True...
-
1. Describe how the various historical restricted stock studies were used by the appraiser to estimate the liquidity discount. 2. What other factors could the appraiser have used to estimate the...
-
Benchmarking how well a company's current strategy is working ( companies like BMW or Toyota ) involves Question 2 2 options: determining whether the company is falling short of its stated financial...
-
Will the industry generate an attractive rate of profit over this period?
-
A corporation's only class of stock is $1 par common stock with 1,000,000 shares authorized, 800,000 shares issued, 600,000 shares outstanding, and treasury stock of 200,000 shares. When the...
-
Identify three roles or activities of the Triune God (Father, Son, and Holy Spirit) in His interaction with human beings as seen in the assigned passages. Support each role or activity with at least...
-
How does the market react to changes in a company's EPS? 14. How can investors use EPS to estimate future earnings and make investment decisions? 15. What are some potential challenges in accurately...
-
A steel cantilever beam, of length 2L, has an I-section, see Figure Q2. The cantilever beam is under a uniformly distributed load q = 265 kN/m applied in its vertical plane of symmetry at OA part of...
-
You are building a Fintech solution(stock screening) and you are exploring the data marketplace. Your Fintech is using fundamental data (Income Statement, Balance Sheet, etc.) and Market Data (Stock...
-
Explain the reasons why Interactive Media has become such a potent medium for doing effective advertising. 3. When you look at the whole picture of consumer market, and you look at all demographic...
-
How would you display the man page for shadow in section 5 of the system manual? How would you change your login shell to tcsh without using root privileges? How many man pages are in the Devices...
-
Citing a scientific article, explain in your own words, how DNA fingerprinting has been used in forensic science to solve crimes and why it may not always be accurate or effective.
-
Alice has been on a long trip without checking her e-mail. She then finds out that she has lost some e-mails or attachments her friends claim they have sent to her. What can be the problem?
-
Draw a bar chart to compare the different downloading data rates of common modems.
-
In Figure 17.5, do we have a loop problem if we change each hub in the LANs to a link-layer switch? Figure 17.5 Figure 17.5 Loop problem in a learning switch a. Station A sends a frame to station D...
-
Barriers to entry do not protect monopolistic competitive firms in the _________ run. Economic profits will _________ new firms to the industry. Similarly, firms will leave when there are economic...
-
When price is greater than average total costs, the monopolistic competitive firm will make an economic _________.
-
Long-run equilibrium in a monopolistic competitive industry occurs when the firm experiences _________ economic profits or losses, which eliminates incentive for firms to _________ or _________ the...
Study smarter with the SolutionInn App