Class STUNResolver
java.lang.Object
org.jivesoftware.smackx.jingleold.nat.TransportResolver
org.jivesoftware.smackx.jingleold.nat.STUNResolver
Transport resolver using the JSTUN library, to discover public IP and use it as a candidate.
The goal of this resolver is to take possible to establish and manage out-of-band connections between two XMPP entities, even if they are behind Network Address Translators (NATs) or firewalls.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
STUN service definition.Nested classes/interfaces inherited from class org.jivesoftware.smackx.jingleold.nat.TransportResolver
TransportResolver.Type
-
Field Summary
Modifier and TypeFieldDescriptionprotected STUNResolver.STUNService
protected int
protected String
protected String
protected Thread
static final String
Fields inherited from class org.jivesoftware.smackx.jingleold.nat.TransportResolver
candidates, CHECK_TIMEOUT, type
-
Constructor Summary
ConstructorDescriptionConstructor with default STUN server.STUNResolver
(int defaultPort) Constructor with a default port. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancel any operation.void
clear()
Clear the list of candidates and start the resolution again.Get the name of the current STUN server.int
Get the port of the current STUN server.void
Initialize the resolver.boolean
Return true if the service is working.Load a list of services: STUN servers and ports.loadSTUNServers
(InputStream stunConfigStream) Load the STUN configuration from a stream.void
resolve
(JingleSession session) Resolve the IP and obtain a valid transport method.void
setSTUNService
(String ip, int port) Set the STUN server name and port.Methods inherited from class org.jivesoftware.smackx.jingleold.nat.TransportResolver
addCandidate, addListener, clearCandidates, getCandidate, getCandidateCount, getCandidates, getCandidatesList, getFreePort, getListenersList, getPreferredCandidate, getType, initializeAndWait, isInitialized, isResolved, removeListener, setInitialized, setResolveEnd, setResolveInit, setType, triggerCandidateAdded
-
Field Details
-
STUNSERVERS_FILENAME
- See Also:
-
currentServer
-
resolverThread
-
defaultPort
-
resolvedPublicIP
-
resolvedLocalIP
-
-
Constructor Details
-
STUNResolver
public STUNResolver()Constructor with default STUN server. -
STUNResolver
Constructor with a default port.- Parameters:
defaultPort
- Port to use by default.
-
-
Method Details
-
isResolving
Return true if the service is working.- Overrides:
isResolving
in classTransportResolver
- Returns:
- true if the resolver is working.
- See Also:
-
setSTUNService
Set the STUN server name and port.- Parameters:
ip
- the STUN server nameport
- the STUN server port
-
getCurrentServerName
Get the name of the current STUN server.- Returns:
- the name of the STUN server
-
getCurrentServerPort
Get the port of the current STUN server.- Returns:
- the port of the STUN server
-
loadSTUNServers
Load the STUN configuration from a stream.- Parameters:
stunConfigStream
- An InputStream with the configuration file.- Returns:
- A list of loaded servers
-
loadSTUNServers
Load a list of services: STUN servers and ports. Some public STUN servers are:iphone-stun.freenet.de:3478 larry.gloo.net:3478 stun.xten.net:3478 stun.fwdnet.net stun.fwd.org (no DNS SRV record) stun01.sipphone.com (no DNS SRV record) stun.softjoys.com (no DNS SRV record) stun.voipbuster.com (no DNS SRV record) stun.voxgratia.org (no DNS SRV record) stun.noc.ams-ix.net
This list should be contained in a file in the "META-INF" directory- Returns:
- a list of services
-
resolve
public void resolve(JingleSession session) throws XMPPException, SmackException.NotConnectedException, InterruptedException Resolve the IP and obtain a valid transport method.- Specified by:
resolve
in classTransportResolver
- Parameters:
session
- the Jingle session.- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.XMPPException
- if an XMPP protocol error was received.
-
initialize
Initialize the resolver.- Specified by:
initialize
in classTransportResolver
- Throws:
XMPPException
- if an XMPP protocol error was received.
-
cancel
Cancel any operation.- Specified by:
cancel
in classTransportResolver
- Throws:
XMPPException
- if an XMPP protocol error was received.- See Also:
-
clear
Clear the list of candidates and start the resolution again.- Overrides:
clear
in classTransportResolver
- Throws:
XMPPException
- if an XMPP protocol error was received.- See Also:
-