use of java.net.DatagramSocket in project robovm by robovm.
the class OldDatagramPacketTest method test_getPort.
public void test_getPort() throws Exception {
DatagramPacket dp = new DatagramPacket("Hello".getBytes(), 5, InetAddress.getLocalHost(), 1000);
assertEquals("Incorrect port returned", 1000, dp.getPort());
final DatagramSocket ss = new DatagramSocket();
Thread thread = new Thread(new Runnable() {
public void run() {
try {
DatagramPacket packet = new DatagramPacket(new byte[256], 256);
ss.setSoTimeout(3000);
ss.receive(packet);
ss.send(packet);
} catch (IOException e) {
System.out.println("thread exception: " + e);
}
}
});
thread.start();
DatagramSocket cs = new DatagramSocket();
try {
byte[] bytes = new byte[] { 1, 2, 3, 4, 5, 6 };
DatagramPacket packet = new DatagramPacket(bytes, 6, InetAddress.getByName("localhost"), ss.getLocalPort());
cs.send(packet);
cs.setSoTimeout(3000);
cs.receive(packet);
cs.close();
assertEquals(packet.getPort(), ss.getLocalPort());
} finally {
cs.close();
ss.close();
}
}
use of java.net.DatagramSocket in project routerkeygenAndroid by routerkeygen.
the class AlcatelLucentKeygen method getKeys.
@Override
public List<String> getKeys() {
if (getMacAddress().length() != 12) {
setErrorCode(R.string.msg_errpirelli);
return null;
}
DNSQuery dnsquery = new DNSQuery(getMacAddress(), 255, 1);
DatagramSocket datagramsocket = null;
try {
datagramsocket = new DatagramSocket();
datagramsocket.setSoTimeout(5000);
int i = 0;
boolean noReply = false;
do {
try {
sendQuery(dnsquery, datagramsocket, InetAddress.getByName("hak.im"));
noReply = true;
} catch (IOException e) {
e.printStackTrace();
}
++i;
if (i >= 3) {
//Give up.
return getResults();
}
} while (!noReply);
getResponse(dnsquery, datagramsocket);
addPassword(NSLookup.getKey(dnsquery));
} catch (IOException e) {
e.printStackTrace();
} finally {
if (datagramsocket != null) {
datagramsocket.close();
}
}
return getResults();
}
use of java.net.DatagramSocket in project spring-framework by spring-projects.
the class SocketUtilsTests method findAvailableUdpPortWhenPortOnLoopbackInterfaceIsNotAvailable.
@Test(expected = IllegalStateException.class)
public void findAvailableUdpPortWhenPortOnLoopbackInterfaceIsNotAvailable() throws Exception {
int port = SocketUtils.findAvailableUdpPort();
DatagramSocket socket = new DatagramSocket(port, InetAddress.getByName("localhost"));
try {
// will only look for the exact port
SocketUtils.findAvailableUdpPort(port, port);
} finally {
socket.close();
}
}
use of java.net.DatagramSocket in project robovm by robovm.
the class DatagramChannelTest method testReceiveSend_Block_Empty_C2S.
public void testReceiveSend_Block_Empty_C2S() throws Exception {
this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
sendByChannel("", localAddr2);
receiveByDatagramSocket(CAPACITY_NORMAL, localAddr2, "");
}
use of java.net.DatagramSocket in project robovm by robovm.
the class DatagramChannelTest method testReceiveSend_NonBlock_Empty_C2S.
public void testReceiveSend_NonBlock_Empty_C2S() throws Exception {
this.channel1.configureBlocking(false);
this.channel2.configureBlocking(false);
this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
sendByChannel("", localAddr2);
receiveByDatagramSocket(CAPACITY_NORMAL, localAddr2, "");
}
Aggregations