java.lang.Object | +--java.net.SocketImpl | +--java.net.PlainSocketImpl | +--java.net.SocksSocketImpl
SOCKS (V4 & V5) TCP socket implementation (RFC 1928). This is a subclass of PlainSocketImpl. Note this class should NOT be public.
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
private boolean
authenticate(byte method,
InputStream in,
DataOutputStream out)
protected void
bind(InetAddress baddr,
int lport)
protected void
connect(InetAddress address,
int port)
protected void
connect(SocketAddress endpoint,
int timeout)
protected void
connect(String host,
int port)
protected void
create(boolean stream)
protected boolean
supportsUrgentData()
private String server
private int port
private InetSocketAddress external_address
private boolean useV4
private Socket cmdsock
private InputStream cmdIn
private OutputStream cmdOut
public static final int PROTO_VERS4
public static final int PROTO_VERS
public static final int DEFAULT_PORT
public static final int NO_AUTH
public static final int GSSAPI
public static final int USER_PASSW
public static final int NO_METHODS
public static final int CONNECT
public static final int BIND
public static final int UDP_ASSOC
public static final int IPV4
public static final int DOMAIN_NAME
public static final int IPV6
public static final int REQUEST_OK
public static final int GENERAL_FAILURE
public static final int NOT_ALLOWED
public static final int NET_UNREACHABLE
public static final int HOST_UNREACHABLE
public static final int CONN_REFUSED
public static final int TTL_EXPIRED
public static final int CMD_NOT_SUPPORTED
public static final int ADDR_TYPE_NOT_SUP
int timeout
public static final int SHUT_RD
public static final int SHUT_WR
SocksSocketImpl(String server, int port)
void setV4()
private void privilegedConnect(String host, int port, int timeout) throws IOException
private void superConnectServer(String host, int port, int timeout) throws IOException
private int readSocksReply(InputStream in, byte[] data) throws IOException
private boolean authenticate(byte method, InputStream in, DataOutputStream out) throws IOException
private void connectV4(InputStream in, OutputStream out, InetSocketAddress endpoint) throws IOException
protected void connect(SocketAddress endpoint, int timeout) throws IOException
connect in class PlainSocketImplendpoint - the SocketAddress to connect to.timeout - the timeout value in milliseconds
IOException - if the connection can't be established.
SecurityException - if there is a security manager and it
doesn't allow the connection
IllegalArgumentException - if endpoint is null or a
SocketAddress subclass not supported by this socketprivate void bindV4(InputStream in, OutputStream out, InetAddress baddr, int lport) throws IOException
protected void bind(InetAddress baddr, int lport) throws IOException
bind in class PlainSocketImplbaddr - the IP address of the remote host.lport - the port number.
IOExceptionprotected void accept(SocketImpl s) throws IOException
accept in class PlainSocketImpls - the accepted connection.
IOExceptionprotected InetAddress getInetAddress()
address field.
getInetAddress in class SocketImpladdress field.java.net.SocketImpl#addressprotected int getPort()
port field.
getPort in class SocketImplport field.java.net.SocketImpl#portprotected int getLocalPort()
SocketImpllocalport field.
getLocalPort in class SocketImpllocalport field.java.net.SocketImpl#localportprotected void close() throws IOException
PlainSocketImpl
close in class PlainSocketImplprotected void create(boolean stream) throws IOException
create in class SocketImplstream - if true, create a stream socket;
otherwise, create a datagram socket.
IOExceptionprotected void connect(String host, int port) throws UnknownHostException, IOException
connect in class SocketImplhost - the specified hostport - the specified port
UnknownHostException
IOExceptionprotected void connect(InetAddress address, int port) throws IOException
connect in class SocketImpladdress - the addressport - the specified port
IOExceptionpublic void setOption(int opt, Object val) throws SocketException
SocketOptionsSocketImpl s; ... s.setOption(SO_LINGER, new Integer(10)); // OK - set SO_LINGER w/ timeout of 10 sec. s.setOption(SO_LINGER, new Double(10)); // ERROR - expects java.lang.IntegerIf the requested option is binary, it can be set using this method by a java.lang.Boolean:
s.setOption(TCP_NODELAY, new Boolean(true)); // OK - enables TCP_NODELAY, a binary option
s.setOption(TCP_NODELAY, new Boolean(false)); // OK - disables TCP_NODELAY s.setOption(SO_LINGER, new Boolean(false)); // OK - disables SO_LINGER
opt - identifies the optionval - the parameter of the socket option
SocketException - if the option is unrecognized,
the socket is closed, or some low-level error occurredSocketOptions.getOption(int)public Object getOption(int opt) throws SocketException
SocketOptions
SocketImpl s;
...
Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY));
if (noDelay.booleanValue()) {
// true if TCP_NODELAY is enabled...
...
}
For options that take a particular type as a parameter, getOption(int) will return the paramter's value, else it will return java.lang.Boolean(false):
Object o = s.getOption(SO_LINGER);
if (o instanceof Integer) {
System.out.print("Linger time is " + ((Integer)o).intValue());
} else {
// the true type of o is java.lang.Boolean(false);
}
opt - an int identifying the option to fetch
SocketException - if the socket is closedSocketOptions.setOption(int, java.lang.Object)protected void listen(int count) throws IOException
listen in class SocketImplcount - the amount of time to listen for connections
IOExceptionprotected InputStream getInputStream() throws IOException
getInputStream in class SocketImplIOExceptionvoid setInputStream(SocketInputStream in)
protected OutputStream getOutputStream() throws IOException
getOutputStream in class SocketImplIOExceptionprotected int available() throws IOException
available in class SocketImplIOExceptionprotected void shutdownInput() throws IOException
shutdownInput in class SocketImplIOExceptionjava.net.Socket#shutdownOutput(),
java.net.Socket#close(),
java.net.Socket#setSoLinger(boolean, int)protected void shutdownOutput() throws IOException
shutdownOutput in class SocketImplIOExceptionjava.net.Socket#shutdownInput(),
java.net.Socket#close(),
java.net.Socket#setSoLinger(boolean, int)protected boolean supportsUrgentData()
SocketImpl
supportsUrgentData in class SocketImpljava.net.SocketImpl#addressprotected void sendUrgentData(int data) throws IOException
SocketImpl
sendUrgentData in class SocketImpldata - The byte of data to send
IOExceptionprotected void finalize() throws IOException
public final FileDescriptor acquireFD()
public final void releaseFD()
public boolean isConnectionReset()
public boolean isConnectionResetPending()
public void setConnectionReset()
public void setConnectionResetPending()
public boolean isClosedOrPending()
public int getTimeout()