List of usage examples for java.net DatagramSocket DatagramSocket
public DatagramSocket(int port) throws SocketException
From source file:net.fenyo.mail4hotspot.dns.DnsListener.java
public void run() { final ExecutorService pool = Executors.newCachedThreadPool(); try {// ww w . j a v a 2 s.c om socket = new DatagramSocket(DNSPORT); } catch (final SocketException ex) { ex.printStackTrace(); log.error("can not start DNS service"); return; } do { final DatagramPacket query = new DatagramPacket(new byte[DATAGRAMMAXSIZE], DATAGRAMMAXSIZE); try { socket.receive(query); pool.execute(new Handler(query)); } catch (IOException ex) { log.error(ex); } } while (thread.isInterrupted() == false); try { log.info("waiting for executor tasks to terminate"); pool.awaitTermination(120, TimeUnit.SECONDS); } catch (InterruptedException ex) { log.error(ex); } }
From source file:org.apache.jmeter.JMeter.java
private static DatagramSocket getSocket(int udpPort, int udpPortMax) { DatagramSocket socket = null; int i = udpPort; while (i <= udpPortMax) { try {// www . ja v a2 s . c o m socket = new DatagramSocket(i); break; } catch (SocketException e) { i++; } } return socket; }
From source file:org.opendaylight.lispflowmapping.integrationtest.MappingServiceIntegrationTest.java
License:asdf
private void sendProxyMapRequest(String rloc, int port, LispAFIAddress adLcaf) throws SocketTimeoutException, SocketException { String eid = "10.1.0.1"; MapRequest mapRequest = createNonProxyMapRequest(eid, adLcaf); sendMapRequest(mapRequest);//from www . j ava 2s. co m DatagramSocket nonProxySocket = new DatagramSocket(new InetSocketAddress(rloc, port)); MapRequest recievedMapRequest = receiveMapRequest(nonProxySocket); assertEquals(mapRequest.getNonce(), recievedMapRequest.getNonce()); assertEquals(mapRequest.getSourceEid(), recievedMapRequest.getSourceEid()); assertEquals(mapRequest.getItrRloc(), recievedMapRequest.getItrRloc()); assertEquals(mapRequest.getEidRecord(), recievedMapRequest.getEidRecord()); nonProxySocket.close(); }
From source file:org.opendaylight.lispflowmapping.integrationtest.MappingServiceIntegrationTest.java
License:asdf
private DatagramSocket initSocket(DatagramSocket socket, int port) { try {/*from w w w. j av a 2 s. c o m*/ socket = new DatagramSocket(new InetSocketAddress(ourAddress, port)); } catch (SocketException e) { e.printStackTrace(); fail(); } return socket; }