The Eclipse IDE has a built-in TCP/IP Monitor tool that allows programmers to intercept communications between client and server through TCP/IP or HTTP protocol in order to monitor, watch and analyze the requests and responses. This article provides the steps which help you to use the TCP/IP monitor for the purpose of monitoring HTTP communications between the client and the server on a localhost machine.

Basically, the TCP/IP monitor acts as a proxy between the client and the server so that it can capture the requests and responses. And the most important thing to remember when using this monitor is that it requires changing the server port at the client side to the port at which the monitor is listening. The following diagram depicts the concepts:

TCP IP Monitor principle

For example, suppose that we need to monitor the HTTP communications of a web application running on localhost (typically under a Tomcat instance inside Eclipse), which would be normally accessed via this URL:

http://localhost:8080/FileUploadSpringMVC

And the TCP/IP Monitor is listening on the port number 9898, therefore we have to replace the port 8080 by 9898 as follows:

http://localhost:9898/FileUploadSpringMVC

If the monitor is running on the port 9898, it will receive the requests and forward them to the destination server at the port configured (8080).

Now, let’s go through the steps in details. Suppose that we want to monitor a web application developed in the tutorial: Spring MVC File Upload Tutorial with Eclipse IDE. The application is deployed on Tomcat server which is listening on the port number 8080.

Setting up a TCP/IP Monitor in Eclipse

Open the TCP/IP Monitor settings by go to the menu Window > Preferences > TCP/IP Monitor:

Select TCP IP Monitor in Preferences

Click Add to create a new monitor. In the New Monitor dialog, enter the following information:

    • Local monitoring port: 9898
    • Host name: localhost
    • Port: 8080
    • Type: HTTP

      New Monitor settings

Click OK to add the new monitor to the list. Select the monitor and then click Start:

Start TCP IP Monitor

When the Status changed to Started, click OK to close the Preferences dialog. Next, click Window > Show View > Other… > TCP/IP Monitor > OK to open up the TCP/IP Monitor view:

Show TCP IP Monitor View

The TCP/IP Monitor view is added to the workspace but there is no information because no communication happens:

Empty TCP IP Monitor view

Now, make sure that the FileUploadSpringMVC application is up and running; open an Internal Web Browser (or an external browser) and type the following URL:

http://localhost:9898/FileUploadSpringMVC

The monitor immediately displays the request and response information as shown in the following screenshot:

HTTP GET request and response in TCP IP Monitor

Now, go back to the browser and try to enter some information and upload two files:

Test FileUploadSpringMVC app

The monitor captures the POST request and HTML response immediately:

POST request and HTML response in TCP IP Monitor

That’s really useful if we want to analyze the raw request and response! In addition, the TCP/IP monitor allows us to modify and resend the request, as well as watch the request/response in different types and encodings. Let experience the monitor further yourself!

To stop the monitor, go to the TCP/IP Monitor settings in the Preferences dialog (or right click inside the TCP/IP Monitor view and select Properties). Then select the monitor you want to stop, and click Stop:

Stop TCP IP Monitor

 

Remember to change the port in the URL back to the regular number (8080) when the monitor is stopped.

Monitoring hosts other than localhost

Is it possible to monitor the communications between the web browser and sites other then the localhost? Oh, certainly! Here’s an example of the settings that are used to monitor the site www.bing.com:

TCP IP Settings to monitor Bing

Now, go to the browser and type the URL as http://localhost:9898, you will see the Bing’s home page! The request and response are captured by the monitor as shown in the following screenshot:

Request and response of Bing site

 

Recommended Book: Eclipse IDE: Eclipse IDE based on Eclipse 4.2 and 4.3 (vogella series) (Volume 2)

Start learning on Udemy today!