Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming Write a program which listens on a TCP port specified at run time. When a connection is made, the server sends back an

Java Programming

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.

ServerSocket sSocket = new ServerSocket(portNumber);

Socket socket = sSocket.accept();

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:

https://gyazo.com/8b56254af64eb9a0433e92782d925e16

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 browser 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 8000 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:8000.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions