public class SocksSocket
extends java.net.Socket
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.
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
localHost |
protected java.net.InetAddress |
localIP |
protected int |
localPort |
protected Proxy |
proxy |
protected java.lang.String |
remoteHost |
protected java.net.InetAddress |
remoteIP |
protected int |
remotePort |
| Modifier | Constructor and Description |
|---|---|
|
SocksSocket(java.net.InetAddress ip,
int port)
Tryies to connect to given ip and port
using default proxy.
|
protected |
SocksSocket(java.net.InetAddress ip,
int port,
Proxy 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.
|
protected |
SocksSocket(java.lang.String host,
int port,
Proxy proxy)
These 2 constructors are used by the SocksServerSocket.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
bind, connect, connect, getChannel, getKeepAlive, getLocalSocketAddress, getOOBInline, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setTrafficClass, shutdownInput, shutdownOutputprotected Proxy proxy
protected java.lang.String localHost
protected java.lang.String remoteHost
protected java.net.InetAddress localIP
protected java.net.InetAddress remoteIP
protected int localPort
protected int remotePort
public SocksSocket(java.lang.String host,
int port)
throws SocksException,
java.net.UnknownHostException
host - Machine to connect to.port - Port to which to connect.SocksExceptionjava.net.UnknownHostExceptionSocksSocket(Proxy,String,int),
Socks5Proxy.resolveAddrLocallypublic 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.java.net.UnknownHostException - If one of the following happens:
SocksException - If one of the following happens:
IOexception - if anything is wrong with I/O.Socks5Proxy.resolveAddrLocallypublic SocksSocket(java.net.InetAddress ip,
int port)
throws SocksException
ip - Machine to connect to.port - Port to which to connect.SocksExceptionSocksSocket(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.SocksExceptionprotected SocksSocket(java.lang.String host,
int port,
Proxy proxy)
protected SocksSocket(java.net.InetAddress ip,
int port,
Proxy proxy)
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.net.Socketjava.io.IOExceptionpublic java.io.InputStream getInputStream()
getInputStream in class java.net.Socketpublic java.io.OutputStream getOutputStream()
getOutputStream in class java.net.Socketpublic int getPort()
getPort in class java.net.Socketpublic java.lang.String getHost()
public java.net.InetAddress getInetAddress()
getInetAddress in class java.net.Socketpublic int getLocalPort()
getLocalPort in class java.net.Socketpublic java.net.InetAddress getLocalAddress()
getLocalAddress in class java.net.Socketpublic java.lang.String getLocalHost()
public void setSoLinger(boolean on,
int val)
throws java.net.SocketException
setSoLinger in class java.net.Socketjava.net.SocketExceptionpublic int getSoLinger(int timeout)
throws java.net.SocketException
java.net.SocketExceptionpublic void setSoTimeout(int timeout)
throws java.net.SocketException
setSoTimeout in class java.net.Socketjava.net.SocketExceptionpublic int getSoTimeout(int timeout)
throws java.net.SocketException
java.net.SocketExceptionpublic void setTcpNoDelay(boolean on)
throws java.net.SocketException
setTcpNoDelay in class java.net.Socketjava.net.SocketExceptionpublic boolean getTcpNoDelay()
throws java.net.SocketException
getTcpNoDelay in class java.net.Socketjava.net.SocketExceptionpublic java.lang.String toString()
toString in class java.net.SocketCopyright © 2012. All Rights Reserved.