How to Use TCPMon for Debugging Web ServicesDebugging web services — whether SOAP, REST over HTTP, or other TCP-based protocols — can be challenging when requests and responses pass through multiple layers: clients, proxies, load balancers, application servers, and middleware. TCPMon is a lightweight, protocol-agnostic tool that lets you intercept, view, and modify raw TCP traffic between a client and a server. This article explains what TCPMon is, when to use it, how to set it up, and practical debugging techniques and examples to help you solve real-world web service problems.
What is TCPMon?
TCPMon is a proxy tool that listens on a local port and forwards TCP traffic to a configured remote host and port while logging the raw request and response bytes. It is protocol-agnostic — it does not parse or modify higher-level protocols by default — which makes it useful for inspecting any TCP-based protocol, including HTTP, SOAP, and custom services.
Advantages:
- Simple to set up and use.
- Works with any TCP protocol.
- Lets you see raw data including headers, payloads, and binary content.
- Can be used to replay requests or test how services react to modified input.
Limitations:
- No deep protocol analysis (compared to Wireshark or specialized HTTP debuggers).
- No built-in TLS interception (unless combined with additional tooling).
- Manual editing and replaying of traffic is limited compared with full-featured tools.
When to use TCPMon
Use TCPMon when:
- You need a quick, lightweight way to observe the exact bytes exchanged between a client and server.
- Higher-level tools (like browser dev tools or application logs) don’t show raw traffic or you suspect middleware is changing requests.
- You’re debugging SOAP web services where seeing the full XML envelope and headers is important.
- You want to capture and replay TCP traffic during functional tests without installing complex sniffers.
Avoid using TCPMon when:
- You require TLS interception or strong protocol-specific parsing (use mitmproxy, Burp Suite, or Wireshark for those cases).
- You need automated, large-scale traffic capture and analysis (use dedicated logging/instrumentation).
Installing and launching TCPMon
There are several implementations and forks of TCPMon. Some are Java-based and shipped as small GUI applications, while others are lightweight command-line utilities. The Java-based TCPMon historically distributed with Apache Axis is still common; many IDEs and repositories host updated variants.
Basic steps (Java GUI variant):
- Ensure you have Java (JRE/JDK) installed (Java 8+ recommended).
- Download tcpmon.jar or the distribution that contains the TCPMon class.
- Launch with:
java -jar tcpmon.jar
- In the GUI, add a new listener/monitor specifying:
- Local listening port (e.g., 8081)
- Remote target host (e.g., api.example.com)
- Remote target port (e.g., 80 or 443 for HTTPS — note TLS needs special handling)
Command-line variants may follow:
tcpmon --listen 8081 --target api.example.com:80
Basic workflow: intercepting HTTP/REST and SOAP
- Choose a local port for TCPMon to listen on (e.g., 8081).
- Configure the target host and port (e.g., api.example.com:80).
- Point your client at localhost:8081 instead of the real endpoint. This can be done by:
- Changing the service endpoint in client configuration.
- Using an HTTP proxy configuration if TCPMon supports it.
- Editing /etc/hosts to map the service hostname to 127.0.0.1 while keeping the port set to TCPMon’s listening port.
- Run the request from your client. TCPMon will accept the connection, forward bytes to the remote server, and display the request and response contents.
- Inspect the logged request/response. For SOAP, you’ll see full XML envelopes; for REST/HTTP you’ll see headers and body. You can copy, edit, and replay if the TCPMon implementation allows.
Example: debugging a failing SOAP call
- Client sends a SOAP request to localhost:8081 (TCPMon).
- TCPMon forwards to real service at api.example.com:80.
- You inspect the SOAP envelope in TCPMon and notice a wrong namespace or missing header.
- Modify client or replay the corrected request to verify the fix.
Inspecting and interpreting TCPMon output
TCPMon typically shows:
- Raw request bytes (headers + payload)
- Raw response bytes (headers + payload)
- Timestamps and connection metadata
Key things to check:
- HTTP status codes and response headers (authentication, caching, content-type).
- Content-length mismatches and chunked transfer encoding anomalies.
- Character encoding issues — look for incorrect Content-Type charset or mojibake.
- SOAP faults and stack traces embedded in XML responses.
- Unexpected redirect responses or proxy authentication challenges.
When data is binary or compressed, you may need to save the raw bytes to a file and open them with appropriate tools (gzip, image viewers, etc.).
Replaying and modifying requests
Some TCPMon variants allow manual editing of the captured request before forwarding or saving the raw bytes for replay. Use this to:
- Test server responses to altered headers (e.g., change User-Agent, Authorization).
- Try different payloads without modifying client code.
- Reproduce intermittent bugs by replaying identical traffic.
If your TCPMon doesn’t support editing, you can:
-
Copy the raw request, save it to a file, and use curl or netcat to replay:
# replay an HTTP request saved in request.txt nc api.example.com 80 < request.txt
-
Use scripting (Python requests, curl) to reconstruct and send modified requests.
Handling HTTPS/TLS
TCPMon does not natively decode TLS traffic because it forwards raw encrypted bytes. Options to inspect HTTPS:
- Use an HTTPS-capable proxy (mitmproxy, Burp) that performs TLS interception and presents a trusted certificate to the client.
- Terminate TLS at a local reverse proxy (e.g., nginx) and forward plain HTTP from that proxy into TCPMon or the backend.
- For development only: configure your service and client to use HTTP or a test certificate the proxy can trust.
Never bypass TLS in production or intercept traffic without authorization.
Advanced debugging scenarios
- Intermittent failures
- Capture multiple request/response cycles with TCPMon and compare them byte-for-byte to find subtle differences (missing header, different cookie, timing issues).
- Large payloads or streaming
- Observe chunked transfer patterns and ensure both client and server properly close streams. Watch for truncated bodies or premature connection closes.
- Character encoding and XML parsing
- Check Content-Type charset and XML prolog. Mismatched encodings can cause parsing errors server-side.
- Authentication and session state
- Inspect Authorization headers, cookies, and Set-Cookie responses. Verify tokens are present and valid for failing requests.
- Middleware interference
- If a reverse proxy modifies headers or strips data, place TCPMon between the client and the proxy to determine where changes occur.
Example: Step-by-step debugging session
Scenario: Your SOAP client gets a 500 Internal Server Error from a production endpoint.
- Start TCPMon listening on 8081 with target production.example.com:80.
- Reconfigure your client endpoint to http://localhost:8081/service.
- Execute the failing operation. TCPMon shows:
- Request: SOAP envelope missing Authorization header.
- Response: 500 with server stack trace mentioning NullPointer in auth module.
- Root cause: client misconfiguration removed the header when proxying. Fix client configuration to include Authorization.
- Re-run request; TCPMon shows header present and server returns 200 with valid SOAP response.
This quick workflow often identifies configuration issues faster than reading logs or debugging on the server.
Alternatives and complementary tools
- Wireshark — packet-level capture with deep protocol decoding (useful when you need transport-level details).
- mitmproxy / Burp Suite — HTTPS interception, request editing, and advanced scripting.
- curl / httpie — quick command-line request construction and replay.
- Postman — GUI for REST testing with scripting and collection runs.
- Server-side logging & tracing — distributed tracing (OpenTelemetry) to correlate client requests and server processing.
Use TCPMon alongside these tools: TCPMon for quick plain-TCP inspection and the others for TLS interception, analysis, or automated testing.
Best practices and security considerations
- Only intercept traffic you own or have explicit permission to inspect.
- Do not use TCPMon to bypass TLS in production systems.
- Sanitize or redact sensitive credentials when saving or sharing captures.
- For reproducibility, save both raw request files and a short description of client/server versions and configurations.
- When debugging intermittent production issues, avoid altering live traffic in ways that could affect users; prefer passive capture or test environments.
Conclusion
TCPMon is a practical, no-friction tool for viewing raw TCP traffic between clients and servers. It excels at quickly revealing exactly what bytes are exchanged, making it ideal for debugging SOAP and plain-HTTP web services, diagnosing header or payload problems, and replaying requests. Pair TCPMon with TLS-capable proxies and packet analyzers for complete coverage, and always follow security best practices when intercepting traffic.
Leave a Reply