Search in sources :

Example 71 with DatagramPacket

use of java.net.DatagramPacket in project camel by apache.

the class SyslogSpringNettyTest method testSendingRawUDP.

@Test
public void testSendingRawUDP() throws IOException, InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:stop1");
    MockEndpoint mock2 = getMockEndpoint("mock:stop2");
    mock.expectedMessageCount(1);
    mock2.expectedMessageCount(1);
    mock2.expectedBodiesReceived(message);
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("localhost");
        for (int i = 0; i < messageCount; i++) {
            byte[] data = message.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
            socket.send(packet);
            Thread.sleep(100);
        }
    } finally {
        socket.close();
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 72 with DatagramPacket

use of java.net.DatagramPacket in project camel by apache.

the class MinaDataFormatTest method testSendingRawUDP.

@Test
public void testSendingRawUDP() throws IOException, InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:syslogReceiver");
    MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
    mock.expectedMessageCount(1);
    mock2.expectedMessageCount(1);
    mock2.expectedBodiesReceived(message);
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            byte[] data = message.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
            socket.send(packet);
            Thread.sleep(100);
        }
    } finally {
        socket.close();
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 73 with DatagramPacket

use of java.net.DatagramPacket in project camel by apache.

the class NettyManyUDPMessagesTest method testSendingManyMessages.

@Test
public void testSendingManyMessages() throws Exception, InterruptedException {
    MockEndpoint stop1 = getMockEndpoint("mock:stop1");
    MockEndpoint stop2 = getMockEndpoint("mock:stop2");
    stop2.expectedMessageCount(messageCount);
    stop1.expectedMessageCount(messageCount);
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            byte[] data = message.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
            socket.send(packet);
            Thread.sleep(100);
        }
    } finally {
        socket.close();
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 74 with DatagramPacket

use of java.net.DatagramPacket in project bigbluebutton by bigbluebutton.

the class UdpSocket method receive.

/** Receives a datagram packet from this socket. */
public void receive(UdpPacket pkt) throws java.io.IOException {
    DatagramPacket dgram = pkt.getDatagramPacket();
    socket.receive(dgram);
    pkt.setDatagramPacket(dgram);
}
Also used : DatagramPacket(java.net.DatagramPacket)

Example 75 with DatagramPacket

use of java.net.DatagramPacket in project RPlay by bencall.

the class AudioServer method request_resend.

/**
	 * Ask iTunes to resend packet
	 * FUNCTIONAL??? NO PROOFS
	 * @param first
	 * @param last
	 */
public void request_resend(int first, int last) {
    System.out.println("Resend Request: " + first + "::" + last);
    if (last < first) {
        return;
    }
    int len = last - first + 1;
    byte[] request = new byte[] { (byte) 0x80, (byte) (0x55 | 0x80), 0x01, 0x00, (byte) ((first & 0xFF00) >> 8), (byte) (first & 0xFF), (byte) ((len & 0xFF00) >> 8), (byte) (len & 0xFF) };
    try {
        DatagramPacket temp = new DatagramPacket(request, request.length, rtpClient, session.getControlPort());
        csock.send(temp);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException)

Aggregations

DatagramPacket (java.net.DatagramPacket)302 IOException (java.io.IOException)126 DatagramSocket (java.net.DatagramSocket)121 InetAddress (java.net.InetAddress)69 SocketException (java.net.SocketException)43 Test (org.junit.Test)35 InetSocketAddress (java.net.InetSocketAddress)34 SocketTimeoutException (java.net.SocketTimeoutException)30 UnknownHostException (java.net.UnknownHostException)21 MulticastSocket (java.net.MulticastSocket)18 InterruptedIOException (java.io.InterruptedIOException)17 SocketAddress (java.net.SocketAddress)15 ByteBuffer (java.nio.ByteBuffer)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)11 PortUnreachableException (java.net.PortUnreachableException)9 ArrayList (java.util.ArrayList)9 SyslogMessageLogDTO (org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO)8 BindException (java.net.BindException)7 Transactional (org.springframework.transaction.annotation.Transactional)7