Search in sources :

Example 61 with DatagramPacket

use of java.net.DatagramPacket in project routerkeygenAndroid by routerkeygen.

the class AlcatelLucentKeygen method sendQuery.

private static void sendQuery(DNSQuery dnsquery, DatagramSocket datagramsocket, InetAddress inetaddress) throws IOException {
    final byte[] query = dnsquery.extractQuery();
    datagramsocket.send(new DatagramPacket(query, query.length, inetaddress, 5353));
}
Also used : DatagramPacket(java.net.DatagramPacket)

Example 62 with DatagramPacket

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

the class PlainDatagramSocketImpl method peek.

@Override
protected int peek(InetAddress sender) throws IOException {
    // We don't actually want the data: we just want the DatagramPacket's filled-in address.
    DatagramPacket packet = new DatagramPacket(EmptyArray.BYTE, 0);
    int result = peekData(packet);
    // Note: evil side-effect on InetAddress! This method should have returned InetSocketAddress!
    sender.ipaddress = packet.getAddress().getAddress();
    return result;
}
Also used : DatagramPacket(java.net.DatagramPacket)

Example 63 with DatagramPacket

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

the class DatagramChannelImpl method receiveDirectImpl.

private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop) throws IOException {
    SocketAddress retAddr = null;
    DatagramPacket receivePacket = new DatagramPacket(EmptyArray.BYTE, 0);
    int oldposition = target.position();
    int received = 0;
    do {
        received = IoBridge.recvfrom(false, fd, target, 0, receivePacket, isConnected());
        if (receivePacket != null && receivePacket.getAddress() != null) {
            // copy the data of received packet
            if (received > 0) {
                target.position(oldposition + received);
            }
            retAddr = receivePacket.getSocketAddress();
            break;
        }
    } while (loop);
    return retAddr;
}
Also used : DatagramPacket(java.net.DatagramPacket) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 64 with DatagramPacket

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

the class OldAndroidDatagramTest method testDatagramSocketSetSOTimeout.

// Regression test for issue 1018003: DatagramSocket ignored a set timeout.
public void testDatagramSocketSetSOTimeout() throws Exception {
    DatagramSocket sock = null;
    int timeout = 5000;
    long start = System.currentTimeMillis();
    try {
        sock = new DatagramSocket();
        DatagramPacket pack = new DatagramPacket(new byte[100], 100);
        sock.setSoTimeout(timeout);
        sock.receive(pack);
    } catch (SocketTimeoutException e) {
        // expected
        long delay = System.currentTimeMillis() - start;
        if (Math.abs(delay - timeout) > 1000) {
            fail("timeout was not accurate. expected: " + timeout + " actual: " + delay + " miliseconds.");
        }
    } finally {
        if (sock != null) {
            sock.close();
        }
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket)

Example 65 with DatagramPacket

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

the class OldDatagramPacketTest method test_setData$B.

public void test_setData$B() {
    DatagramPacket dp = new DatagramPacket("Hello".getBytes(), 5);
    try {
        dp.setData(null);
        fail("NullPointerException was not thrown.");
    } catch (NullPointerException expected) {
    }
}
Also used : DatagramPacket(java.net.DatagramPacket)

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