JMU
Proxies in Java
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
The Participants
Proxy Types
The Mechanism
The Mechanism (cont.)

An HTTP Example

  // 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

  
The Mechanism (cont.)

A TCP Example

  // 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

  
Dynamic Proxy Selection