Code example for DatagramSocket

Methods: sendsetSoTimeout

0
	public static boolean doUDPKnock (InetAddress host, int port, int timeout) {
		DatagramSocket s;
		// do everything in threes (why not? -- won't send any of it anyways...) 
		byte[] empty = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
		try { 
			s = new DatagramSocket();
			s.setSoTimeout(timeout);
			// s.connect(host, port); 
			s.send(new DatagramPacket(empty, 0, empty.length, host, port));
		} catch (IllegalArgumentException ex) {
			// should be here, since this means the packet was blocked the the 
			// host firewall 
		} catch (SocketException ex) {
			return false; 
		} catch (IOException ex) {
			return false; 
		} 
		return true; 
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE