Program for proxy server in java




















The request from the client will be received by Input Stream, so once we are connected, we will be sending this Input Stream which is nothing but a normal HTTP REQ object to the server which has the resource or as in our case the machine connected to Internet.

We will be forwarding this output stream to the client which will be rendered in the application which the client requested in. That is if the request was sent through command line, the entire HTML will be printed, if its a browser the page will be rendered. Make sure to close all the opened sockets and connections once the response is sent.

Since this whole code is running in an infinite loop, the server will keep on waiting for the requests and sending the responses back. This is a crude implementation of the concept and there is room for a lot more improvements like supporting SSL , but this should serve as a foundation to make the proxy a robust one.

We can easily make this Java class as a Win32 service, so that it will always run in background and starts along with the OS. That will need some work with JNI. I do understand how a proxy should work. It basically should be in the middle of a browser and a website. It must work as a two way channel. The basic need is just to be a transparent tunnel. The extra capabilities should be an ability to edit headers and filter some websites or IPs.

Add a comment. Active Oldest Votes. Hope that helps! The first paragraph is really the core of any thread-per-connection server, not just a proxy server! Thats very nice for the start. I've edited my first question and added some code. I will really appreciate if you can take a look and guide me how to continue from there.

The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Improve Article. Save Article. Like Article. Last Updated : 28 Apr, It never returns. PrintWriter out. A separate. Attention reader! Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

Previous Greenhouse Effect. Next Serialization of Lambda Expression in Java. Recommended Articles. Article Contributed By :.



0コメント

  • 1000 / 1000