• Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing proxy server with Java? ("Intercepting" sockets)  RSS feed

 
joseph lam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does anyone know how to open a socket in Java so another program can use the same port on which the socket was opened? In other words, what if you want to write a load balancer in Java to "intercept" all requests through port 80 without modifying, e.g., apache's code. Since apache make native system calls to listen on port 80, it seems that we might have to somehow replace that native code with the Java proxy (perhaps using JNI to talk to the replacement piece). Ideas, anyone?

Thanks in advance,
Joe

p.s. How do products such as ZoneAlarm do it for all ports?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A proxy server is easy. One would configure Apache (for example) to listen to another port, say 8080. The proxy would listen to port 80. When a connection is made to port 80, the proxy creates another connection to port 8080 and pass the result back to the client on 80. There's a number of Java Proxy Servers. Several are open source so you can see how they work.
Something like ZoneAlarm is very different. Java doesn't have low-level socket access so you'd need to use a native language and get smart on the OS's native API.
[ February 22, 2007: Message edited by: Joe Ess ]
 
joseph lam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

It seems that we either have to modify the os kernel or relying on capabilities of an os that support this kind of "plugin", i.e., native api to insert custom defined "filters"/"interceptors" on ports.

Thanks for the idea of rerouting requests by changing application ports around but I was hoping to find a solution that doesn't require modify code or configuration, i.e., the intercepted application is unaware of this, and it's transparent...

I just started looking into a linux solution called "divert sockets". And consider how zonealarm did it, I have a sneaking suspicion that Windows provides API for registering custom define "socket filters" - ANYONE WHO IS A WINDOWS EXPERT HERE who can confirm this?

Thanks.
-Joe
 
Paulo Pontes
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a very similar need. How did you worked out this?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!