Proxies in Java
An Introduction |
Prof. David Bernstein |
Computer Science Department |
bernstdh@jmu.edu |
Proxy.Type.HTTP
Proxy.Type.SOCKS
Proxy.Type.DIRECT
SocketAddress
Proxy
Proxy
:
URLConnection
or a Socket
URLConnection
or Socket
to connect()
through the Proxy
// Getting Started SocketAddress address = new InetSocketAddress(proxyname, proxyport); Proxy proxy = new Proxy(Proxy.Type.HTTP, address); // Using the Proxy URL url = new URL(resource); URLConnection conn = url.openConnection(proxy); // Use the URLConnection
// Getting Started SocketAddress address = new InetSocketAddress(hostname, port); Proxy proxy = new Proxy(Proxy.Type.SOCKS, address); // Using the Proxy Socket socket = new Socket(proxy); SocketAddress server = new InetSocketAddress(servername, serverport); socket.connect(server); // Use the Socket