Question: Use Java to write a program which listens on a TCP port specified at run time. When a connection is made, the server sends back
Use Java to write a program which listens on a TCP port specified at run time. When a connection is made, the server sends back an HTTP 200 response and HTML text, which when shown in a browser, will display:
"Your IP address is:" followed by the IP address of the machine that has connected. The IP address of the client may be obtained by using the getInetAddress method in the Socket class.
It should then print the current date and time. In order to obtain the current date and time, you can use the java Date class.
For example, when I try the program on my own computer, I see:
Your IP address is 129.32.95.12
It is now: Mon Oct 10 13:45:19 EDT 2016
You should be able to test your program with a web browser to see that it's doing what it should.
Remember that your program is probably not going to be able to listen on port 80. You'll want to pick a relatively high port (i.e., something between 2000 and 65000).
On the client side, To tell the web brower to connect to a web server on an alternate port, append a ":" and the port number to the URL. For example, if you're running the server on port 9999 on your home computer or workstation in the lab, and you're running a web browser on the same machine, you'd type in the browser's location window http://127.0.0.1:9999.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
