public class Socks5DatagramSocket extends DatagramSocket
SOCKS5 protocol allows to send host address as either:
NOTE:
Unlike other SOCKS Sockets, it does not support proxy chaining,
and will throw an exception if proxy has a chain proxy attached. The
reason for that is not my laziness, but rather the restrictions of
the SOCKSv5 protocol. Basicaly SOCKSv5 proxy server, needs to know from
which host:port datagrams will be send for association, and returns address
to which datagrams should be send by the client, but it does not
inform client from which host:port it is going to send datagrams, in fact
there is even no guarantee they will be send at all and from the same address
each time.
Constructor and Description |
---|
Socks5DatagramSocket()
Construct Datagram socket for communication over SOCKS5 proxy
server.
|
Socks5DatagramSocket(int port)
Construct Datagram socket for communication over SOCKS5 proxy
server.
|
Socks5DatagramSocket(int port,
InetAddress ip)
Construct Datagram socket for communication over SOCKS5 proxy
server.
|
Socks5DatagramSocket(Proxy p,
int port,
InetAddress ip)
Constructs datagram socket for communication over specified proxy.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes datagram socket, and proxy connection.
|
InetAddress |
getLocalAddress()
Address assigned by the proxy, to which datagrams are send for relay.
|
int |
getLocalPort()
Returns port assigned by the proxy, to which datagrams are relayed.
|
boolean |
isProxyAlive(int timeout)
This method checks wether proxy still runs udp forwarding service
for this socket.
|
void |
receive(DatagramPacket dp)
Receives udp packet.
|
void |
send(DatagramPacket dp)
Sends the Datagram either through the proxy or directly depending
on current proxy settings and destination address.
|
void |
send(DatagramPacket dp,
String host)
This method allows to send datagram packets with address type DOMAINNAME.
|
bind, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass
public Socks5DatagramSocket() throws SocksException, IOException
SocksException
IOException
public Socks5DatagramSocket(int port) throws SocksException, IOException
SocksException
IOException
public Socks5DatagramSocket(int port, InetAddress ip) throws SocksException, IOException
SocksException
IOException
public Socks5DatagramSocket(Proxy p, int port, InetAddress ip) throws SocksException, IOException
SocksException
IOException
public void send(DatagramPacket dp) throws IOException
See documentation on java.net.DatagramSocket for full details on how to use this method.
send
in class DatagramSocket
dp
- Datagram to send.IOException
- If error happens with I/O.public void send(DatagramPacket dp, String host) throws IOException
If proxy specified for that socket has an option resolveAddrLocally set to true host will be resolved, and the datagram will be send with address type IPV4, if resolve fails, UnknownHostException is thrown.
dp
- Datagram to send, it should contain valid port and datahost
- Host name to which datagram should be send.IOException
- If error happens with I/O, or the host can't be
resolved when proxy settings say that hosts should be resolved locally.Socks5Proxy.resolveAddrLocally(boolean)
public void receive(DatagramPacket dp) throws IOException
receive
in class DatagramSocket
dp
- Datagram in which all relevent information will be copied.IOException
public int getLocalPort()
getLocalPort
in class DatagramSocket
public InetAddress getLocalAddress()
getLocalAddress
in class DatagramSocket
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class DatagramSocket
public boolean isProxyAlive(int timeout)
This methods checks wether the primary connection to proxy server is active. If it is, chances are that proxy continues to forward datagrams being send from this socket. If it was closed, most likely datagrams are no longer being forwarded by the server.
Proxy might decide to stop forwarding datagrams, in which case it should close primary connection. This method allows to check, wether this have been done.
You can specify timeout for which we should be checking EOF condition on the primary connection. Timeout is in milliseconds. Specifying 0 as timeout implies infinity, in which case method will block, until connection to proxy is closed or an error happens, and then return false.
One possible scenario is to call isProxyactive(0) in separate thread, and once it returned notify other threads about this event.
timeout
- For how long this method should block, before returning.Copyright © 2024. All rights reserved.