org.lastbamboo.common.turn.client
Class TcpTurnClient

java.lang.Object
  extended by org.littleshoot.stun.stack.message.StunMessageVisitorAdapter<org.littleshoot.stun.stack.message.StunMessage>
      extended by org.lastbamboo.common.turn.client.TcpTurnClient
All Implemented Interfaces:
EventListener, org.lastbamboo.common.stun.client.StunClient, TurnClient, org.littleshoot.mina.common.IoServiceListener, org.littleshoot.stun.stack.message.StunMessageVisitor<org.littleshoot.stun.stack.message.StunMessage>, org.littleshoot.stun.stack.StunAddressProvider

public class TcpTurnClient
extends org.littleshoot.stun.stack.message.StunMessageVisitorAdapter<org.littleshoot.stun.stack.message.StunMessage>
implements TurnClient, org.littleshoot.mina.common.IoServiceListener

Class that handles all responsibilities of a TURN client. It does this in a couple of ways. First, it opens a connection to the TURN server and allocates a binding on the TURN server. Second, it decodes Data Indication messages arriving from the TURN server. When it receives a message, it creates sockets to the local HTTP server and forwards the data (HTTP data) enclosed in the Data Indication to the local HTTP server.

If this ever loses the connection to the TURN server, it notifies the listener that maintains TURN connections.


Constructor Summary
TcpTurnClient(TurnClientListener clientListener, org.littleshoot.util.CandidateProvider<InetSocketAddress> candidateProvider, org.littleshoot.mina.filter.codec.ProtocolCodecFactory codecFactory)
          Creates a new TCP TURN client.
 
Method Summary
 void addIoServiceListener(org.littleshoot.mina.common.IoServiceListener serviceListener)
           
 void close()
          Closes this client's connection to the TURN server.
 void connect()
           
 InetSocketAddress getHostAddress()
           
 InetSocketAddress getMappedAddress()
          Accesses the MAPPED ADDRESS attribute returned from the TURN server.
 InetSocketAddress getRelayAddress()
          Accesses the allocated address for this TURN client on the TURN server.
 InetSocketAddress getServerReflexiveAddress()
           
 InetAddress getStunServerAddress()
          Gets the address of the STUN server this TURN client is using.
 boolean hostPortMapped()
           
 boolean isConnected()
          Returns whether or not the TURN client is connected.
 void sendConnectRequest(InetSocketAddress remoteAddress)
          Tells the client to send a Connect Request for the specified remote address, telling the TURN server to attempt to connect to the specified address and to allow incoming connections from that address.
 void serviceActivated(org.littleshoot.mina.common.IoService service, SocketAddress serviceAddress, org.littleshoot.mina.common.IoHandler handler, org.littleshoot.mina.common.IoServiceConfig config)
           
 void serviceDeactivated(org.littleshoot.mina.common.IoService service, SocketAddress serviceAddress, org.littleshoot.mina.common.IoHandler handler, org.littleshoot.mina.common.IoServiceConfig config)
           
 void sessionCreated(org.littleshoot.mina.common.IoSession session)
           
 void sessionDestroyed(org.littleshoot.mina.common.IoSession session)
           
 org.littleshoot.stun.stack.message.StunMessage visitAllocateErrorResponse(org.littleshoot.stun.stack.message.turn.AllocateErrorResponse response)
           
 org.littleshoot.stun.stack.message.StunMessage visitAllocateSuccessResponse(org.littleshoot.stun.stack.message.turn.AllocateSuccessResponse response)
           
 org.littleshoot.stun.stack.message.StunMessage visitConnectionStatusIndication(org.littleshoot.stun.stack.message.turn.ConnectionStatusIndication indication)
           
 org.littleshoot.stun.stack.message.StunMessage visitDataIndication(org.littleshoot.stun.stack.message.turn.DataIndication data)
           
 org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress remoteAddress)
           
 org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress remoteAddress, long rto)
           
 
Methods inherited from class org.littleshoot.stun.stack.message.StunMessageVisitorAdapter
visitAllocateRequest, visitBindingErrorResponse, visitBindingRequest, visitBindingSuccessResponse, visitCanceledMessage, visitConnectErrorMesssage, visitConnectRequest, visitNullMessage, visitSendIndication
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpTurnClient

public TcpTurnClient(TurnClientListener clientListener,
                     org.littleshoot.util.CandidateProvider<InetSocketAddress> candidateProvider,
                     org.littleshoot.mina.filter.codec.ProtocolCodecFactory codecFactory)
Creates a new TCP TURN client.

Parameters:
clientListener - The listener for TURN client events.
candidateProvider - The class that provides TURN candidate servers.
codecFactory - The codec factory.
Method Detail

connect

public void connect()
             throws IOException
Specified by:
connect in interface org.lastbamboo.common.stun.client.StunClient
Throws:
IOException

close

public void close()
Description copied from interface: TurnClient
Closes this client's connection to the TURN server.

Specified by:
close in interface TurnClient
Specified by:
close in interface org.littleshoot.stun.stack.StunAddressProvider

sendConnectRequest

public void sendConnectRequest(InetSocketAddress remoteAddress)
Description copied from interface: TurnClient
Tells the client to send a Connect Request for the specified remote address, telling the TURN server to attempt to connect to the specified address and to allow incoming connections from that address.

Specified by:
sendConnectRequest in interface TurnClient
Parameters:
remoteAddress - The address of the remote host.

getRelayAddress

public InetSocketAddress getRelayAddress()
Description copied from interface: TurnClient
Accesses the allocated address for this TURN client on the TURN server.

Specified by:
getRelayAddress in interface TurnClient
Specified by:
getRelayAddress in interface org.littleshoot.stun.stack.StunAddressProvider
Returns:
The address the TURN server allocated on this client's behalf.

getMappedAddress

public InetSocketAddress getMappedAddress()
Description copied from interface: TurnClient
Accesses the MAPPED ADDRESS attribute returned from the TURN server. This is the server reflexive, or public address.

Specified by:
getMappedAddress in interface TurnClient
Returns:
The address and port returned in the MAPPED ADDRESS attribute.

visitAllocateSuccessResponse

public org.littleshoot.stun.stack.message.StunMessage visitAllocateSuccessResponse(org.littleshoot.stun.stack.message.turn.AllocateSuccessResponse response)
Specified by:
visitAllocateSuccessResponse in interface org.littleshoot.stun.stack.message.StunMessageVisitor<org.littleshoot.stun.stack.message.StunMessage>
Overrides:
visitAllocateSuccessResponse in class org.littleshoot.stun.stack.message.StunMessageVisitorAdapter<org.littleshoot.stun.stack.message.StunMessage>

visitAllocateErrorResponse

public org.littleshoot.stun.stack.message.StunMessage visitAllocateErrorResponse(org.littleshoot.stun.stack.message.turn.AllocateErrorResponse response)
Specified by:
visitAllocateErrorResponse in interface org.littleshoot.stun.stack.message.StunMessageVisitor<org.littleshoot.stun.stack.message.StunMessage>
Overrides:
visitAllocateErrorResponse in class org.littleshoot.stun.stack.message.StunMessageVisitorAdapter<org.littleshoot.stun.stack.message.StunMessage>

visitConnectionStatusIndication

public org.littleshoot.stun.stack.message.StunMessage visitConnectionStatusIndication(org.littleshoot.stun.stack.message.turn.ConnectionStatusIndication indication)
Specified by:
visitConnectionStatusIndication in interface org.littleshoot.stun.stack.message.StunMessageVisitor<org.littleshoot.stun.stack.message.StunMessage>
Overrides:
visitConnectionStatusIndication in class org.littleshoot.stun.stack.message.StunMessageVisitorAdapter<org.littleshoot.stun.stack.message.StunMessage>

visitDataIndication

public org.littleshoot.stun.stack.message.StunMessage visitDataIndication(org.littleshoot.stun.stack.message.turn.DataIndication data)
Specified by:
visitDataIndication in interface org.littleshoot.stun.stack.message.StunMessageVisitor<org.littleshoot.stun.stack.message.StunMessage>
Overrides:
visitDataIndication in class org.littleshoot.stun.stack.message.StunMessageVisitorAdapter<org.littleshoot.stun.stack.message.StunMessage>

serviceActivated

public void serviceActivated(org.littleshoot.mina.common.IoService service,
                             SocketAddress serviceAddress,
                             org.littleshoot.mina.common.IoHandler handler,
                             org.littleshoot.mina.common.IoServiceConfig config)
Specified by:
serviceActivated in interface org.littleshoot.mina.common.IoServiceListener

serviceDeactivated

public void serviceDeactivated(org.littleshoot.mina.common.IoService service,
                               SocketAddress serviceAddress,
                               org.littleshoot.mina.common.IoHandler handler,
                               org.littleshoot.mina.common.IoServiceConfig config)
Specified by:
serviceDeactivated in interface org.littleshoot.mina.common.IoServiceListener

sessionCreated

public void sessionCreated(org.littleshoot.mina.common.IoSession session)
Specified by:
sessionCreated in interface org.littleshoot.mina.common.IoServiceListener

sessionDestroyed

public void sessionDestroyed(org.littleshoot.mina.common.IoSession session)
Specified by:
sessionDestroyed in interface org.littleshoot.mina.common.IoServiceListener

getStunServerAddress

public InetAddress getStunServerAddress()
Description copied from interface: TurnClient
Gets the address of the STUN server this TURN client is using.

Specified by:
getStunServerAddress in interface TurnClient
Specified by:
getStunServerAddress in interface org.littleshoot.stun.stack.StunAddressProvider
Returns:
The address of the STUN server.

getHostAddress

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

getServerReflexiveAddress

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

write

public org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request,
                                                            InetSocketAddress remoteAddress)
Specified by:
write in interface org.lastbamboo.common.stun.client.StunClient

write

public org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request,
                                                            InetSocketAddress remoteAddress,
                                                            long rto)
Specified by:
write in interface org.lastbamboo.common.stun.client.StunClient

isConnected

public boolean isConnected()
Description copied from interface: TurnClient
Returns whether or not the TURN client is connected. A TURN client is only considered "connected" if it has successfully allocated a port on the TURN server for relaying data.

Specified by:
isConnected in interface TurnClient
Returns:
true if the TURN client is connected to its server, otherwise false.

hostPortMapped

public boolean hostPortMapped()

addIoServiceListener

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


Copyright © 2013 LittleShoot. All Rights Reserved.