KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > socks > Socks4Proxy


1 package socks;
2 import java.net.*;
3 import java.io.*;
4 import java.util.Hashtable JavaDoc;
5 import java.util.Enumeration JavaDoc;
6
7 /**
8   Proxy which describes SOCKS4 proxy.
9 */

10
11 public class Socks4Proxy extends Proxy implements Cloneable JavaDoc{
12
13 //Data members
14
String JavaDoc user;
15
16 //Public Constructors
17
//====================
18

19    /**
20      Creates the SOCKS4 proxy
21      @param p Proxy to use to connect to this proxy, allows proxy chaining.
22      @param proxyHost Address of the proxy server.
23      @param proxyPort Port of the proxy server
24      @param user User name to use for identification purposes.
25      @throws UnknownHostException If proxyHost can't be resolved.
26     */

27    public Socks4Proxy(Proxy p,String JavaDoc proxyHost,int proxyPort,String JavaDoc user)
28           throws UnknownHostException{
29       super(p,proxyHost,proxyPort);
30       this.user = new String JavaDoc(user);
31       version = 4;
32    }
33
34    /**
35      Creates the SOCKS4 proxy
36      @param proxyHost Address of the proxy server.
37      @param proxyPort Port of the proxy server
38      @param user User name to use for identification purposes.
39      @throws UnknownHostException If proxyHost can't be resolved.
40     */

41    public Socks4Proxy(String JavaDoc proxyHost,int proxyPort,String JavaDoc user)
42           throws UnknownHostException{
43       this(null,proxyHost,proxyPort,user);
44    }
45
46    /**
47      Creates the SOCKS4 proxy
48      @param p Proxy to use to connect to this proxy, allows proxy chaining.
49      @param proxyIP Address of the proxy server.
50      @param proxyPort Port of the proxy server
51      @param user User name to use for identification purposes.
52     */

53    public Socks4Proxy(Proxy p,InetAddress proxyIP,int proxyPort,String JavaDoc user){
54       super(p,proxyIP,proxyPort);
55       this.user = new String JavaDoc(user);
56       version = 4;
57    }
58
59    /**
60      Creates the SOCKS4 proxy
61      @param proxyIP Address of the proxy server.
62      @param proxyPort Port of the proxy server
63      @param user User name to use for identification purposes.
64     */

65    public Socks4Proxy(InetAddress proxyIP,int proxyPort,String JavaDoc user){
66       this(null,proxyIP,proxyPort,user);
67    }
68
69 //Public instance methods
70
//========================
71

72    /**
73     * Creates a clone of this proxy. Changes made to the clone should not
74     * affect this object.
75     */

76    public Object JavaDoc clone(){
77       Socks4Proxy newProxy = new Socks4Proxy(proxyIP,proxyPort,user);
78       newProxy.directHosts = (InetRange)directHosts.clone();
79       newProxy.chainProxy = chainProxy;
80       return newProxy;
81    }
82
83
84 //Public Static(Class) Methods
85
//==============================
86

87
88 //Protected Methods
89
//=================
90

91    protected Proxy copy(){
92        Socks4Proxy copy = new Socks4Proxy(proxyIP,proxyPort,user);
93        copy.directHosts = this.directHosts;
94        copy.chainProxy = chainProxy;
95        return copy;
96     }
97
98    protected ProxyMessage formMessage(int cmd,InetAddress ip,int port){
99        switch(cmd){
100          case SOCKS_CMD_CONNECT:
101            cmd = Socks4Message.REQUEST_CONNECT;
102          break;
103          case SOCKS_CMD_BIND:
104            cmd = Socks4Message.REQUEST_BIND;
105          break;
106          default:
107            return null;
108        }
109        return new Socks4Message(cmd,ip,port,user);
110    }
111    protected ProxyMessage formMessage(int cmd,String JavaDoc host,int port)
112              throws UnknownHostException{
113        return formMessage(cmd,InetAddress.getByName(host),port);
114    }
115    protected ProxyMessage formMessage(InputStream in)
116              throws SocksException,
117                     IOException{
118        return new Socks4Message(in,true);
119    }
120
121 }
122
Popular Tags