This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
Author

Acessing a socket from another program

Paulo Pontes
Greenhorn

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
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Paulo Pontes
Greenhorn

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: 14114
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Acessing a socket from another program