Code example for DatagramSocket

Methods: sendsetSoTimeout

	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.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; 
Experience pair programming with AI  Get Codota for Java