|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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.
Field Summary | |
static int |
ADDR_TYPE_NOT_SUP
|
static int |
BIND
|
static int |
CMD_NOT_SUPPORTED
|
private InputStream |
cmdIn
|
private OutputStream |
cmdOut
|
private Socket |
cmdsock
|
static int |
CONN_REFUSED
|
static int |
CONNECT
|
static int |
DEFAULT_PORT
|
static int |
DOMAIN_NAME
|
private InetSocketAddress |
external_address
|
static int |
GENERAL_FAILURE
|
static int |
GSSAPI
|
static int |
HOST_UNREACHABLE
|
static int |
IPV4
|
static int |
IPV6
|
static int |
NET_UNREACHABLE
|
static int |
NO_AUTH
|
static int |
NO_METHODS
|
static int |
NOT_ALLOWED
|
private int |
port
|
static int |
PROTO_VERS
|
static int |
PROTO_VERS4
|
static int |
REQUEST_OK
|
private String |
server
|
static int |
SHUT_RD
|
static int |
SHUT_WR
|
(package private) int |
timeout
|
static int |
TTL_EXPIRED
|
static int |
UDP_ASSOC
|
static int |
USER_PASSW
|
private boolean |
useV4
|
Fields inherited from class java.net.SocketImpl |
address, fd, localport, serverSocket, socket |
Fields inherited from interface java.net.SocketOptions |
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 |
Constructor Summary | |
(package private) |
SocksSocketImpl(String server,
int port)
|
Method Summary | |
protected void |
accept(SocketImpl s)
Accepts a connection. |
FileDescriptor |
acquireFD()
|
private boolean |
authenticate(byte method,
InputStream in,
DataOutputStream out)
Provides the authentication machanism required by the proxy. |
protected int |
available()
Returns the number of bytes that can be read without blocking. |
protected void |
bind(InetAddress baddr,
int lport)
Binds this socket to the specified port number on the specified host. |
private void |
bindV4(InputStream in,
OutputStream out,
InetAddress baddr,
int lport)
|
protected void |
close()
Closes the socket. |
protected void |
connect(InetAddress address,
int port)
Creates a socket and connects it to the specified address on the specified port. |
protected void |
connect(SocketAddress endpoint,
int timeout)
Connects the Socks Socket to the specified endpoint. |
protected void |
connect(String host,
int port)
Creates a socket and connects it to the specified port on the specified host. |
private void |
connectV4(InputStream in,
OutputStream out,
InetSocketAddress endpoint)
|
protected void |
create(boolean stream)
Creates a socket with a boolean that specifies whether this is a stream socket (true) or an unconnected UDP socket (false). |
protected void |
finalize()
Cleans up if the user forgets to close it. |
protected InetAddress |
getInetAddress()
Returns the value of this socket's address field. |
protected InputStream |
getInputStream()
Gets an InputStream for this socket. |
protected int |
getLocalPort()
Returns the value of this socket's localport field. |
Object |
getOption(int opt)
Fetch the value of an option. |
protected OutputStream |
getOutputStream()
Gets an OutputStream for this socket. |
protected int |
getPort()
Returns the value of this socket's port field. |
int |
getTimeout()
|
boolean |
isClosedOrPending()
|
boolean |
isConnectionReset()
|
boolean |
isConnectionResetPending()
|
protected void |
listen(int count)
Listens, for a specified amount of time, for connections. |
private void |
privilegedConnect(String host,
int port,
int timeout)
|
private int |
readSocksReply(InputStream in,
byte[] data)
|
void |
releaseFD()
|
protected void |
sendUrgentData(int data)
Send one byte of urgent data on the socket. |
void |
setConnectionReset()
|
void |
setConnectionResetPending()
|
(package private) void |
setInputStream(SocketInputStream in)
|
void |
setOption(int opt,
Object val)
Enable/disable the option specified by optID. |
(package private) void |
setV4()
|
protected void |
shutdownInput()
Shutdown read-half of the socket connection; |
protected void |
shutdownOutput()
Shutdown write-half of the socket connection; |
private void |
superConnectServer(String host,
int port,
int timeout)
|
protected boolean |
supportsUrgentData()
Returns whether or not this SocketImpl supports sending urgent data. |
Methods inherited from class java.net.SocketImpl |
getFileDescriptor, getServerSocket, getSocket, reset, setServerSocket, setSocket, toString |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
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
Constructor Detail |
SocksSocketImpl(String server, int port)
Method Detail |
void setV4()
private void privilegedConnect(String host, int port, int timeout) throws IOException
IOException
private void superConnectServer(String host, int port, int timeout) throws IOException
IOException
private int readSocksReply(InputStream in, byte[] data) throws IOException
IOException
private boolean authenticate(byte method, InputStream in, DataOutputStream out) throws IOException
IOException
private void connectV4(InputStream in, OutputStream out, InetSocketAddress endpoint) throws IOException
IOException
protected void connect(SocketAddress endpoint, int timeout) throws IOException
connect
in class PlainSocketImpl
endpoint
- 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
IOException
protected void bind(InetAddress baddr, int lport) throws IOException
bind
in class PlainSocketImpl
baddr
- the IP address of the remote host.lport
- the port number.
IOException
- if an I/O error occurs when binding this socket.protected void accept(SocketImpl s) throws IOException
accept
in class PlainSocketImpl
s
- the accepted connection.
IOException
- if an I/O error occurs when accepting the
connection.protected InetAddress getInetAddress()
address
field.
getInetAddress
in class SocketImpl
address
field.SocketImpl.address
protected int getPort()
port
field.
getPort
in class SocketImpl
port
field.SocketImpl.port
protected int getLocalPort()
SocketImpl
localport
field.
getLocalPort
in class SocketImpl
localport
field.SocketImpl.localport
protected void close() throws IOException
PlainSocketImpl
close
in class PlainSocketImpl
IOException
protected void create(boolean stream) throws IOException
create
in class SocketImpl
stream
- if true
, create a stream socket;
otherwise, create a datagram socket.
IOException
- if an I/O error occurs while creating the
socket.protected void connect(String host, int port) throws UnknownHostException, IOException
connect
in class SocketImpl
host
- the specified hostport
- the specified port
IOException
- if an I/O error occurs when connecting to the
remote host.
UnknownHostException
protected void connect(InetAddress address, int port) throws IOException
connect
in class SocketImpl
address
- the addressport
- the specified port
IOException
- if an I/O error occurs when attempting a
connection.public void setOption(int opt, Object val) throws SocketException
SocketOptions
SocketImpl 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 optID is unknown along the
protocol stack (including the SocketImpl)SocketOptions.setOption(int, java.lang.Object)
protected void listen(int count) throws IOException
listen
in class SocketImpl
count
- the amount of time to listen for connections
IOException
- if an I/O error occurs when creating the queue.protected InputStream getInputStream() throws IOException
getInputStream
in class SocketImpl
IOException
- if an I/O error occurs when creating the
input stream.void setInputStream(SocketInputStream in)
protected OutputStream getOutputStream() throws IOException
getOutputStream
in class SocketImpl
IOException
- if an I/O error occurs when creating the
output stream.protected int available() throws IOException
available
in class SocketImpl
IOException
- if an I/O error occurs when determining the
number of bytes available.protected void shutdownInput() throws IOException
shutdownInput
in class SocketImpl
IOException
- if an I/O error occurs when shutting down this
socket.Socket.shutdownOutput()
,
Socket.close()
,
Socket.setSoLinger(boolean, int)
protected void shutdownOutput() throws IOException
shutdownOutput
in class SocketImpl
IOException
- if an I/O error occurs when shutting down this
socket.Socket.shutdownInput()
,
Socket.close()
,
Socket.setSoLinger(boolean, int)
protected boolean supportsUrgentData()
SocketImpl
supportsUrgentData
in class SocketImpl
SocketImpl.address
protected void sendUrgentData(int data) throws IOException
SocketImpl
sendUrgentData
in class SocketImpl
data
- The byte of data to send
IOException
- if there is an error
sending the data.protected void finalize() throws IOException
finalize
in class Object
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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |