- Last Updated on 29 April 2014
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:
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:
And the TCP/IP Monitor is listening on the port number 9898, therefore we have to replace the port 8080 by 9898 as follows:
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:
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
Click OK to add the new monitor to the list. Select the monitor and then click Start:
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:
The TCP/IP Monitor view is added to the workspace but there is no information because no communication happens:
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:
The monitor immediately displays the request and response information as shown in the following screenshot:
Now, go back to the browser and try to enter some information and upload two files:
The monitor captures the POST request and HTML response immediately:
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:
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:
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: