我有一個任務用java編寫代理服務器。我必須能夠讀取和修改http頭並阻止提供的黑名單上的一些網站。用Java編寫代理服務器 - 如何?
我用java的經驗,但從來沒有與HTTP,插座,連接端口等工作..
已經幾天試用谷歌一些例子或教程,但我覺得要麼是非常簡單和唐沒有全面的能力,或者非常複雜或不能工作。
你能幫我一些相關的例子,鏈接,教程等...?
我也注意到,我發現一個網頁與開源代理服務器,但他們並沒有真正的工作或非常複雜。
謝謝!
編輯:
您好,我發現一些代碼,偵聽來自瀏覽器來連接並開始一個新的線程爲每個連接。
public class Main {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean listening = true;
int port = 10000; //default
try {
port = Integer.parseInt(args[0]);
} catch (Exception e) {
//ignore me
}
try {
serverSocket = new ServerSocket(port);
System.out.println("Started on: " + port);
} catch (IOException e) {
System.err.println("Could not listen on port: " + args[0]);
System.exit(-1);
}
while (listening) {
new ProxyThreadServer(serverSocket.accept()).start();
}
serverSocket.close();
}
}
的一部分,我真的很困惑與是如何轉移的請求到服務器(URL),從它那裏得到的響應併發送到瀏覽器的響應。
所以基本上我需要4個步驟:
Listen and get the request from a browser.
Forward the request to the web-server.
Get the response from the web server.
Send the response to the browser.
額外的功能正在與頁眉和阻止某些聯繫。但是,開始時這4個步驟將會很好。
這是太開放和模糊的話題在這裏。你有關於如何寫一小部分的問題嗎?您是否瞭解代理服務器的工作原理,例如_什麼它?_ – 2011-04-23 20:33:01
嗨,經過一段時間之後。我確實瞭解代理如何工作。它基本上應該在瀏覽器和網站的中間。它必須作爲雙向渠道運作。基本的需求就是成爲一個透明的隧道。額外的功能應該是能夠編輯標題和過濾一些網站或IP。 – Gil 2011-04-23 21:28:59