src/net/java/sip/communicator/service/protocol/media/TransportManager.java
/**
     * Sends empty UDP packets to target destination data/control ports in order
     * to open ports on NATs or and help RTP proxies latch onto our RTP ports.
     *
     * @param target <tt>MediaStreamTarget</tt>
     * @param type the {@link MediaType} of the connector we'd like to send the
     * hole punching packet through.
     * @param packet (optional) use a pre-generated packet that will be sent
     */
Sends empty UDP packets to target destination data/control ports in order
to open ports on NATs or and help RTP proxies latch onto our RTP ports.

@param target MediaStreamTarget
@param type the  MediaType of the connector we'd like to send the
hole punching packet through.
@param packet (optional) use a pre-generated packet that will be sent
Sends empty UDP packets to target destination data / control ports in order to open ports on NATs or and help RTP proxies latch onto our RTP ports . @param target MediaStreamTarget @param type the MediaType of the connector we ' d like to send the hole punching packet through . @param packet ( optional ) use a pre - generated packet that will be sent
public void sendHolePunchPacket(
        MediaStreamTarget target, MediaType type, RawPacket packet)
    {
        logger.info("Send NAT hole punch packets");
        int packetCount
            = ProtocolMediaActivator.getConfigurationService().getInt(
                    HOLE_PUNCH_PKT_COUNT_PROPERTY,
                    DEFAULT_HOLE_PUNCH_PKT_COUNT);
        if (packetCount < 0)
            packetCount = DEFAULT_HOLE_PUNCH_PKT_COUNT;
        if (packetCount == 0)
            return;
        try
        {
            final StreamConnector connector = getStreamConnector(type);
            if(connector.getProtocol() == StreamConnector.Protocol.TCP)
                return;
            byte[] buf;
            if (packet != null)
                buf = packet.getBuffer();
            else
                buf = new byte[0];
            synchronized(connector)
            {
                for(int i=0; i < packetCount; i++)
                {
                    DatagramSocket socket;
                    if((socket = connector.getDataSocket()) != null)
                    {
                        InetSocketAddress dataAddress = target.getDataAddress();
                        socket.send(
                                new DatagramPacket(
                                        buf,
                                        buf.length,
                                        dataAddress.getAddress(),
                                        dataAddress.getPort()));
                    }
                    if((socket = connector.getControlSocket()) != null)
                    {
                        InetSocketAddress controlAddress
                            = target.getControlAddress();
                        socket.send(
                                new DatagramPacket(
                                        buf,
                                        buf.length,
                                        controlAddress.getAddress(),
                                        controlAddress.getPort()));
                    }
                }
            }
        }
        catch(Exception e)
        {
            logger.error("Error cannot send to remote peer", e);
        }
    }
public void sendHolePunchPacket ( MediaStreamTarget target , MediaType type , RawPacket packet ) { logger . info ( "Send NAT hole punch packets" ) ; int packetCount = ProtocolMediaActivator . getConfigurationService ( ) . getInt ( HOLE_PUNCH_PKT_COUNT_PROPERTY , DEFAULT_HOLE_PUNCH_PKT_COUNT ) ; if ( packetCount < 0 ) packetCount = DEFAULT_HOLE_PUNCH_PKT_COUNT ; if ( packetCount == 0 ) return ; try { final StreamConnector connector = getStreamConnector ( type ) ; if ( connector . getProtocol ( ) == StreamConnector . Protocol . TCP ) return ; byte [ ] buf ; if ( packet != null ) buf = packet . getBuffer ( ) ; else buf = new byte [ 0 ] ; synchronized ( connector ) { for ( int i = 0 ; i < packetCount ; i ++ ) { DatagramSocket socket ; if ( ( socket = connector . getDataSocket ( ) ) != null ) { InetSocketAddress dataAddress = target . getDataAddress ( ) ; socket . send ( new DatagramPacket ( buf , buf . length , dataAddress . getAddress ( ) , dataAddress . getPort ( ) ) ) ; } if ( ( socket = connector . getControlSocket ( ) ) != null ) { InetSocketAddress controlAddress = target . getControlAddress ( ) ; socket . send ( new DatagramPacket ( buf , buf . length , controlAddress . getAddress ( ) , controlAddress . getPort ( ) ) ) ; } } } } catch ( Exception e ) { logger . error ( "Error cannot send to remote peer" , e ) ; } }
Sends empty UDP packets to target destination data/control ports in order
 to open ports on NATs or and help RTP proxies latch onto our RTP ports.
Sends empty UDP packets to target destination data / control ports in order to open ports on NATs or and help RTP proxies latch onto our RTP ports .
//check how many hole punch packets we would be supposed to send: //we may want to send more than one packet in case they get lost // data/RTP // control/RTCP