Search in sources :

Example 36 with DatagramSocket

use of java.net.DatagramSocket in project jcollectd by collectd.

the class ReceiverTest method testBound.

public void testBound() throws Exception {
    DatagramSocket socket = getReceiver().getSocket();
    assertTrue(socket.isBound());
    getLog().info("Bound to LocalPort=" + socket.getLocalPort() + ", LocalAddress=" + socket.getLocalAddress().getHostAddress());
}
Also used : DatagramSocket(java.net.DatagramSocket)

Example 37 with DatagramSocket

use of java.net.DatagramSocket in project jcollectd by collectd.

the class ReceiverTest method createSocket.

protected DatagramSocket createSocket() throws IOException {
    DatagramSocket socket = new DatagramSocket();
    _receiver.setListenAddress("127.0.0.1");
    return socket;
}
Also used : DatagramSocket(java.net.DatagramSocket)

Example 38 with DatagramSocket

use of java.net.DatagramSocket in project jcollectd by collectd.

the class ReceiverTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _receiver = new UdpReceiver();
    DatagramSocket socket = createSocket();
    _receiver.setSocket(socket);
    _receiverThread = new ReceiverThread();
    _receiverThread.start();
}
Also used : DatagramSocket(java.net.DatagramSocket)

Example 39 with DatagramSocket

use of java.net.DatagramSocket in project Smack by igniterealtime.

the class JingleManagerTest method testRTPBridge.

/**
     * RTP Bridge Test
     */
public void testRTPBridge() {
    resetCounter();
    try {
        ProviderManager.getInstance().addIQProvider(RTPBridge.NAME, RTPBridge.NAMESPACE, new RTPBridge.Provider());
        RTPBridge response = RTPBridge.getRTPBridge(getConnection(0), "102");
        class Listener implements Runnable {

            private byte[] buf = new byte[5000];

            private DatagramSocket dataSocket;

            private DatagramPacket packet;

            public Listener(DatagramSocket dataSocket) {
                this.dataSocket = dataSocket;
            }

            public void run() {
                try {
                    while (true) {
                        // Block until a datagram appears:
                        packet = new DatagramPacket(buf, buf.length);
                        dataSocket.receive(packet);
                        incCounter();
                    }
                } catch (Exception e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
            }
        }
        try {
            byte[] packet = { 0, 0, 1, 1, 1, 1, 1 };
            DatagramSocket ds0 = new DatagramSocket(14004, InetAddress.getByName("0.0.0.0"));
            DatagramSocket ds1 = new DatagramSocket(14050, InetAddress.getByName("0.0.0.0"));
            DatagramPacket echo0 = new DatagramPacket(packet, packet.length, InetAddress.getLocalHost(), response.getPortA());
            DatagramPacket echo1 = new DatagramPacket(packet, packet.length, InetAddress.getLocalHost(), response.getPortB());
            ds1.send(echo1);
            ds0.send(echo0);
            Thread.sleep(500);
            Thread t0 = new Thread(new Listener(ds0));
            Thread t1 = new Thread(new Listener(ds1));
            t0.start();
            t1.start();
            int repeat = 300;
            for (int i = 0; i < repeat; i++) {
                ds0.send(echo0);
                ds1.send(echo1);
                Thread.sleep(200);
            }
            System.out.println(valCounter());
            assertTrue(valCounter() == repeat * 2 + 1);
            t0.stop();
            t1.stop();
            ds0.close();
            ds1.close();
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
}
Also used : JingleSessionListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionListener) JingleSessionRequestListener(org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener) PacketListener(org.jivesoftware.smack.PacketListener) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) XMPPException(org.jivesoftware.smack.XMPPException) RTPBridge(org.jivesoftware.smackx.jingle.nat.RTPBridge)

Example 40 with DatagramSocket

use of java.net.DatagramSocket in project Smack by igniterealtime.

the class AudioMediaSession method createSession.

/**
     * Create a Session using Speex Codec.
     *
     * @param localhost    localHost
     * @param localPort    localPort
     * @param remoteHost   remoteHost
     * @param remotePort   remotePort
     * @param eventHandler eventHandler
     * @param quality      quality
     * @param secure       secure
     * @param micOn        micOn
     * @return MediaSession
     * @throws NoProcessorException
     * @throws UnsupportedFormatException
     * @throws IOException
     * @throws GeneralSecurityException
     */
public static MediaSession createSession(String localhost, int localPort, String remoteHost, int remotePort, MediaSessionListener eventHandler, int quality, boolean secure, boolean micOn) throws NoProcessorException, UnsupportedFormatException, IOException, GeneralSecurityException {
    SpeexFormat.setFramesPerPacket(1);
    /**
         * The master key. Hardcoded for now.
         */
    byte[] masterKey = new byte[] { (byte) 0xE1, (byte) 0xF9, 0x7A, 0x0D, 0x3E, 0x01, (byte) 0x8B, (byte) 0xE0, (byte) 0xD6, 0x4F, (byte) 0xA3, 0x2C, 0x06, (byte) 0xDE, 0x41, 0x39 };
    /**
         * The master salt. Hardcoded for now.
         */
    byte[] masterSalt = new byte[] { 0x0E, (byte) 0xC6, 0x75, (byte) 0xAD, 0x49, (byte) 0x8A, (byte) 0xFE, (byte) 0xEB, (byte) 0xB6, (byte) 0x96, 0x0B, 0x3A, (byte) 0xAB, (byte) 0xE6 };
    DatagramSocket[] localPorts = MediaSession.getLocalPorts(InetAddress.getByName(localhost), localPort);
    MediaSession session = MediaSession.createInstance(remoteHost, remotePort, localPorts, quality, secure, masterKey, masterSalt);
    session.setListener(eventHandler);
    session.setSourceDescription(new SourceDescription[] { new SourceDescription(SourceDescription.SOURCE_DESC_NAME, "Superman", 1, false), new SourceDescription(SourceDescription.SOURCE_DESC_EMAIL, "cdcie.tester@je.jfcom.mil", 1, false), new SourceDescription(SourceDescription.SOURCE_DESC_LOC, InetAddress.getByName(localhost) + " Port " + session.getLocalDataPort(), 1, false), new SourceDescription(SourceDescription.SOURCE_DESC_TOOL, "JFCOM CDCIE Audio Chat", 1, false) });
    return session;
}
Also used : MediaSession(mil.jfcom.cie.media.session.MediaSession) JingleMediaSession(org.jivesoftware.smackx.jingleold.media.JingleMediaSession) DatagramSocket(java.net.DatagramSocket) SourceDescription(javax.media.rtp.rtcp.SourceDescription)

Aggregations

DatagramSocket (java.net.DatagramSocket)294 DatagramPacket (java.net.DatagramPacket)137 IOException (java.io.IOException)112 SocketException (java.net.SocketException)74 InetAddress (java.net.InetAddress)63 InetSocketAddress (java.net.InetSocketAddress)46 UnknownHostException (java.net.UnknownHostException)33 Test (org.junit.Test)27 SocketTimeoutException (java.net.SocketTimeoutException)24 InterruptedIOException (java.io.InterruptedIOException)18 PortUnreachableException (java.net.PortUnreachableException)18 ServerSocket (java.net.ServerSocket)18 BindException (java.net.BindException)16 IllegalBlockingModeException (java.nio.channels.IllegalBlockingModeException)16 DatagramChannel (java.nio.channels.DatagramChannel)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 MulticastSocket (java.net.MulticastSocket)10 SocketAddress (java.net.SocketAddress)9 ByteBuffer (java.nio.ByteBuffer)8 ArrayList (java.util.ArrayList)6