org.lastbamboo.common.stun.client
Class UdpStunClient

java.lang.Object
  extended by org.lastbamboo.common.stun.client.UdpStunClient
All Implemented Interfaces:
StunClient, org.littleshoot.stun.stack.StunAddressProvider, org.littleshoot.stun.stack.transaction.StunTransactionListener

public class UdpStunClient
extends Object
implements StunClient, org.littleshoot.stun.stack.transaction.StunTransactionListener

Abstract STUN client. Subclasses typically define transports.


Constructor Summary
UdpStunClient(org.littleshoot.util.CandidateProvider<InetSocketAddress> stunServerCandidateProvider)
          Creates a new STUN client that connects to the specified STUN servers.
UdpStunClient(Collection<InetSocketAddress> stunServers)
          Creates a new STUN client that connects to the specified STUN servers.
UdpStunClient(InetSocketAddress... stunServers)
          Creates a new STUN client that connects to the specified STUN servers.
UdpStunClient(org.littleshoot.stun.stack.transaction.StunTransactionTracker<org.littleshoot.stun.stack.message.StunMessage> transactionTracker, org.littleshoot.mina.common.IoHandler ioHandler, org.littleshoot.util.CandidateProvider<InetSocketAddress> stunServerCandidateProvider)
          Creates a new STUN client for ICE processing.
 
Method Summary
 void addIoServiceListener(org.littleshoot.mina.common.IoServiceListener serviceListener)
           
 void close()
           
 void connect()
           
 InetSocketAddress getHostAddress()
           
 InetSocketAddress getRelayAddress()
           
 InetSocketAddress getServerReflexiveAddress()
           
 InetAddress getStunServerAddress()
           
 boolean hostPortMapped()
           
 Object onTransactionFailed(org.littleshoot.stun.stack.message.StunMessage request, org.littleshoot.stun.stack.message.StunMessage response)
           
 Object onTransactionSucceeded(org.littleshoot.stun.stack.message.StunMessage request, org.littleshoot.stun.stack.message.StunMessage response)
           
protected  void waitIfNoResponse(org.littleshoot.stun.stack.message.StunMessage request, long waitTime)
           
 org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress remoteAddress)
          Writes a STUN binding request.
 org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress remoteAddress, long rto)
          Writes a STUN binding request with the RTO value used for retransmissions explicitly set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UdpStunClient

public UdpStunClient(org.littleshoot.stun.stack.transaction.StunTransactionTracker<org.littleshoot.stun.stack.message.StunMessage> transactionTracker,
                     org.littleshoot.mina.common.IoHandler ioHandler,
                     org.littleshoot.util.CandidateProvider<InetSocketAddress> stunServerCandidateProvider)
              throws IOException
Creates a new STUN client for ICE processing. This client is capable of obtaining "server reflexive" and "host" candidates. We don't use relaying for UDP, so this does not currently support generating "relayed" candidates.

Parameters:
transactionTracker - The transaction tracker to use.
ioHandler - The IoHandler to use.
stunServerCandidateProvider - Provider for STUN server addresses.
Throws:
IOException - If we can't get a STUN server address.

UdpStunClient

public UdpStunClient(org.littleshoot.util.CandidateProvider<InetSocketAddress> stunServerCandidateProvider)
              throws IOException
Creates a new STUN client that connects to the specified STUN servers.

Parameters:
stunServerCandidateProvider - Class that provides STUN servers to use.
Throws:
IOException - If we can't get a STUN server address.

UdpStunClient

public UdpStunClient(InetSocketAddress... stunServers)
              throws IOException
Creates a new STUN client that connects to the specified STUN servers.

Parameters:
stunServerCandidateProvider - Class that provides STUN servers to use.
Throws:
IOException - If we can't get a STUN server address.

UdpStunClient

public UdpStunClient(Collection<InetSocketAddress> stunServers)
              throws IOException
Creates a new STUN client that connects to the specified STUN servers.

Parameters:
stunServerCandidateProvider - Class that provides STUN servers to use.
Throws:
IOException - If we can't get a STUN server address.
Method Detail

connect

public void connect()
             throws IOException
Specified by:
connect in interface StunClient
Throws:
IOException

getHostAddress

public InetSocketAddress getHostAddress()
Specified by:
getHostAddress in interface org.littleshoot.stun.stack.StunAddressProvider

getStunServerAddress

public InetAddress getStunServerAddress()
Specified by:
getStunServerAddress in interface org.littleshoot.stun.stack.StunAddressProvider

waitIfNoResponse

protected void waitIfNoResponse(org.littleshoot.stun.stack.message.StunMessage request,
                                long waitTime)

onTransactionFailed

public Object onTransactionFailed(org.littleshoot.stun.stack.message.StunMessage request,
                                  org.littleshoot.stun.stack.message.StunMessage response)
Specified by:
onTransactionFailed in interface org.littleshoot.stun.stack.transaction.StunTransactionListener

onTransactionSucceeded

public Object onTransactionSucceeded(org.littleshoot.stun.stack.message.StunMessage request,
                                     org.littleshoot.stun.stack.message.StunMessage response)
Specified by:
onTransactionSucceeded in interface org.littleshoot.stun.stack.transaction.StunTransactionListener

addIoServiceListener

public final void addIoServiceListener(org.littleshoot.mina.common.IoServiceListener serviceListener)
Specified by:
addIoServiceListener in interface StunClient

close

public void close()
Specified by:
close in interface org.littleshoot.stun.stack.StunAddressProvider

getServerReflexiveAddress

public InetSocketAddress getServerReflexiveAddress()
                                            throws IOException
Specified by:
getServerReflexiveAddress in interface org.littleshoot.stun.stack.StunAddressProvider
Throws:
IOException

write

public org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request,
                                                            InetSocketAddress remoteAddress)
                                                     throws IOException
Description copied from interface: StunClient
Writes a STUN binding request. This uses the default STUN RTO value of 100ms.

Specified by:
write in interface StunClient
Parameters:
request - The STUN binding request.
remoteAddress - The address to send the request to.
Returns:
The response message.
Throws:
IOException - If there's an IO error writing the message.

write

public org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request,
                                                            InetSocketAddress remoteAddress,
                                                            long rto)
                                                     throws IOException
Description copied from interface: StunClient
Writes a STUN binding request with the RTO value used for retransmissions explicitly set.

Specified by:
write in interface StunClient
Parameters:
request - The STUN binding request.
remoteAddress - The address to send the request to.
rto - The value to use for RTO when calculating retransmission times. Note this only applies to UDP.
Returns:
The response message.
Throws:
IOException - If there's an IO error writing the message.

getRelayAddress

public InetSocketAddress getRelayAddress()
Specified by:
getRelayAddress in interface org.littleshoot.stun.stack.StunAddressProvider

hostPortMapped

public boolean hostPortMapped()


Copyright © 2013 LittleShoot. All Rights Reserved.