Search in sources :

Example 11 with DatagramPacket

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

the class UDPListener method run.

public void run() {
    boolean fin = stopThread;
    while (!fin) {
        byte[] buffer = new byte[MAX_PACKET];
        DatagramPacket p = new DatagramPacket(buffer, buffer.length);
        try {
            synchronized (socket) {
                if (socket != null) {
                    socket.receive(p);
                    delegate.packetReceived(socket, p);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Stop
        synchronized (this) {
            fin = this.stopThread;
        }
    }
}
Also used : DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException)

Example 12 with DatagramPacket

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

the class AutomatedConversionTest method testSendingRawUDP.

@Test
public void testSendingRawUDP() throws IOException, InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:syslogReceiver");
    MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
    mock.expectedMessageCount(2);
    mock2.expectedMessageCount(2);
    mock2.expectedBodiesReceived(rfc3164Message, rfc5424Message);
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            byte[] data = rfc3164Message.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
            socket.send(packet);
            Thread.sleep(100);
        }
        for (int i = 0; i < messageCount; i++) {
            byte[] data = rfc5424Message.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 13 with DatagramPacket

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

the class SyslogSpringMinaTest 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 14 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 15 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)

Aggregations

DatagramPacket (java.net.DatagramPacket)332 IOException (java.io.IOException)137 DatagramSocket (java.net.DatagramSocket)136 InetAddress (java.net.InetAddress)75 SocketException (java.net.SocketException)48 Test (org.junit.Test)37 InetSocketAddress (java.net.InetSocketAddress)34 SocketTimeoutException (java.net.SocketTimeoutException)30 UnknownHostException (java.net.UnknownHostException)26 MulticastSocket (java.net.MulticastSocket)19 InterruptedIOException (java.io.InterruptedIOException)17 SocketAddress (java.net.SocketAddress)16 ByteBuffer (java.nio.ByteBuffer)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 SyslogConnection (org.opennms.netmgt.syslogd.api.SyslogConnection)11 ArrayList (java.util.ArrayList)10 PortUnreachableException (java.net.PortUnreachableException)9 SyslogMessageLogDTO (org.opennms.netmgt.syslogd.api.SyslogMessageLogDTO)8 BindException (java.net.BindException)7 Transactional (org.springframework.transaction.annotation.Transactional)7