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;
}
}
}
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();
}
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();
}
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();
}
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();
}
Aggregations