File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Acessing a socket from another program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Acessing a socket from another program" Watch "Acessing a socket from another program" New topic

Acessing a socket from another program

Paulo Pontes

Joined: Dec 06, 2004
Posts: 20
How can I make a socket that "hears" the communication done by another program?

It will almost act as a sniffer, but just for one communication channel.

Eventually I will need also to send data, "impersonating" the other process. This will allow me to automate certain tedious tasks that the original aplication requires us to do...

Thanks for any help
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

You could write a simple proxy. Rather than having the client connect directly to the server on port 80, for example:
SERVER (someserver:80) <----- CLIENT
The client connects to the proxy, which forwards requests to the server:
SERVER (someserver:80) <----- PROXY (anotherserver:8080) <----- CLIENT
The proxy can record any traffic between the two.

[How To Ask Questions On JavaRanch]
Paulo Pontes

Joined: Dec 06, 2004
Posts: 20
the client is completely closed, I cant change anything in it...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

So if you can't touch the client, and you can't even configure it differently, maybe you could do this: change the address / port of the server, and put your proxy on the original address of the server.

So, suppose the client connects to port 80 of the server:
SERVER (someserver:80) <----- CLIENT

You change the address of the server and put your proxy in place:
SERVER (anotherserver:8080) <----- PROXY (someserver:80) <----- CLIENT

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Acessing a socket from another program
It's not a secret anymore!