Search in sources :

Example 41 with DatagramPacket

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

the class Mina2SslContextParametersUdpTest method sendUdpMessages.

protected void sendUdpMessages() throws Exception {
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            String text = "Hello Message: " + Integer.toString(i);
            byte[] data = text.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
            socket.send(packet);
        }
        Thread.sleep(2000);
    } finally {
        socket.close();
    }
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 42 with DatagramPacket

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

the class Mina2UdpTest method sendUdpMessages.

protected void sendUdpMessages() throws Exception {
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            String text = "Hello Message: " + Integer.toString(i);
            byte[] data = text.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
            socket.send(packet);
        }
        Thread.sleep(2000);
    } finally {
        socket.close();
    }
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 43 with DatagramPacket

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

the class MinaUdpTest method sendUdpMessages.

protected void sendUdpMessages() throws Exception {
    DatagramSocket socket = new DatagramSocket();
    try {
        InetAddress address = InetAddress.getByName("127.0.0.1");
        for (int i = 0; i < messageCount; i++) {
            String text = "Hello Message: " + i;
            byte[] data = text.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
            socket.send(packet);
            Thread.sleep(100);
        }
    } finally {
        socket.close();
    }
}
Also used : DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 44 with DatagramPacket

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

the class TestUdpServer method testRequest.

static void testRequest(XDR request, XDR request2) {
    try {
        DatagramSocket clientSocket = new DatagramSocket();
        InetAddress IPAddress = InetAddress.getByName("localhost");
        byte[] sendData = request.getBytes();
        byte[] receiveData = new byte[65535];
        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Nfs3Constant.SUN_RPCBIND);
        clientSocket.send(sendPacket);
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        clientSocket.receive(receivePacket);
        clientSocket.close();
    } catch (UnknownHostException e) {
        System.err.println("Don't know about host: localhost.");
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Couldn't get I/O for " + "the connection to: localhost.");
        System.exit(1);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Example 45 with DatagramPacket

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

the class TestPortmap method testRegistration.

@Test(timeout = 1000)
public void testRegistration() throws IOException, InterruptedException {
    XDR req = new XDR();
    RpcCall.getInstance(++xid, RpcProgramPortmap.PROGRAM, RpcProgramPortmap.VERSION, RpcProgramPortmap.PMAPPROC_SET, new CredentialsNone(), new VerifierNone()).write(req);
    PortmapMapping sent = new PortmapMapping(90000, 1, PortmapMapping.TRANSPORT_TCP, 1234);
    sent.serialize(req);
    byte[] reqBuf = req.getBytes();
    DatagramSocket s = new DatagramSocket();
    DatagramPacket p = new DatagramPacket(reqBuf, reqBuf.length, pm.getUdpServerLoAddress());
    try {
        s.send(p);
    } finally {
        s.close();
    }
    // Give the server a chance to process the request
    Thread.sleep(100);
    boolean found = false;
    @SuppressWarnings("unchecked") Map<String, PortmapMapping> map = (Map<String, PortmapMapping>) Whitebox.getInternalState(pm.getHandler(), "map");
    for (PortmapMapping m : map.values()) {
        if (m.getPort() == sent.getPort() && PortmapMapping.key(m).equals(PortmapMapping.key(sent))) {
            found = true;
            break;
        }
    }
    Assert.assertTrue("Registration failed", found);
}
Also used : DatagramSocket(java.net.DatagramSocket) XDR(org.apache.hadoop.oncrpc.XDR) VerifierNone(org.apache.hadoop.oncrpc.security.VerifierNone) DatagramPacket(java.net.DatagramPacket) CredentialsNone(org.apache.hadoop.oncrpc.security.CredentialsNone) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DatagramPacket (java.net.DatagramPacket)334 DatagramSocket (java.net.DatagramSocket)138 IOException (java.io.IOException)137 InetAddress (java.net.InetAddress)77 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