|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.net.Socket | +--socks.SocksSocket
SocksSocket tryies to look very similar to normal Socket, while allowing connections through the SOCKS4 or 5 proxy. To use this class you will have to identify proxy you need to use, Proxy class allows you to set default proxy, which will be used by all Socks aware sockets. You can also create either Socks4Proxy or Socks5Proxy, and use them by passing to the appropriate constructors.
Using Socks package can be as easy as that:
import Socks.*; .... try{ //Specify SOCKS5 proxy Proxy.setDefaultProxy("socks-proxy",1080); //OR you still use SOCKS4 //Code below uses SOCKS4 proxy //Proxy.setDefaultProxy("socks-proxy",1080,userName); Socket s = SocksSocket("some.host.of.mine",13); readTimeFromSock(s); }catch(SocksException sock_ex){ //Usually it will turn in more or less meaningfull message System.err.println("SocksException:"+sock_ex); }
However if the need exist for more control, like resolving addresses remotely, or using some non-trivial authentication schemes, it can be done.
Constructor Summary | |
SocksSocket(java.net.InetAddress ip,
int port)
Tryies to connect to given ip and port using default proxy. |
|
SocksSocket(Proxy p,
java.net.InetAddress ip,
int port)
Connects to given ip and port using given Proxy server. |
|
SocksSocket(Proxy p,
java.lang.String host,
int port)
Connects to host port using given proxy server. |
|
SocksSocket(java.lang.String host,
int port)
Tryies to connect to given host and port using default proxy. |
Method Summary | |
void |
close()
Same as Socket |
java.lang.String |
getHost()
Returns remote host name, it is usefull in cases when addresses are resolved by proxy, and we can't create InetAddress object. |
java.net.InetAddress |
getInetAddress()
Get remote host as InetAddress object, might return null if addresses are resolved by proxy, and it is not possible to resolve it locally |
java.io.InputStream |
getInputStream()
Same as Socket |
java.net.InetAddress |
getLocalAddress()
Get address assigned by proxy to make a remote connection, it might be different from the host specified for the proxy. |
java.lang.String |
getLocalHost()
Get name of the host, proxy has assigned to make a remote connection for this socket. |
int |
getLocalPort()
Get the port assigned by the proxy for the socket, not the port on locall machine as in Socket. |
java.io.OutputStream |
getOutputStream()
Same as Socket |
int |
getPort()
Same as Socket |
int |
getSoLinger(int timeout)
Same as socket. |
int |
getSoTimeout(int timeout)
Same as socket. |
boolean |
getTcpNoDelay()
Same as socket. |
void |
setSoLinger(boolean on,
int val)
Same as socket. |
void |
setSoTimeout(int timeout)
Same as socket. |
void |
setTcpNoDelay(boolean on)
Same as socket. |
java.lang.String |
toString()
Get string representation of the socket. |
Methods inherited from class java.net.Socket |
getReceiveBufferSize,
getSendBufferSize,
getSoLinger,
getSoTimeout,
setReceiveBufferSize,
setSendBufferSize,
setSocketImplFactory |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public SocksSocket(java.lang.String host, int port) throws SocksException, java.net.UnknownHostException
host
- Machine to connect to.port
- Port to which to connect.SocksSocket(Proxy,String,int)
,
Socks5Proxy.resolveAddrLocally(boolean)
public SocksSocket(Proxy p, java.lang.String host, int port) throws SocksException, java.net.UnknownHostException
p
- Proxy to use.host
- Machine to connect to.port
- Port to which to connect.Socks5Proxy.resolveAddrLocally(boolean)
public SocksSocket(java.net.InetAddress ip, int port) throws SocksException
ip
- Machine to connect to.port
- Port to which to connect.SocksSocket(Proxy,String,int)
public SocksSocket(Proxy p, java.net.InetAddress ip, int port) throws SocksException
p
- Proxy to use.ip
- Machine to connect to.port
- Port to which to connect.Method Detail |
public void close() throws java.io.IOException
public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public int getPort()
public java.lang.String getHost()
public java.net.InetAddress getInetAddress()
public int getLocalPort()
public java.net.InetAddress getLocalAddress()
public java.lang.String getLocalHost()
public void setSoLinger(boolean on, int val) throws java.net.SocketException
public int getSoLinger(int timeout) throws java.net.SocketException
public void setSoTimeout(int timeout) throws java.net.SocketException
public int getSoTimeout(int timeout) throws java.net.SocketException
public void setTcpNoDelay(boolean on) throws java.net.SocketException
public boolean getTcpNoDelay() throws java.net.SocketException
public java.lang.String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |