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