List of usage examples for java.net DatagramPacket DatagramPacket
public DatagramPacket(byte buf[], int length, InetAddress address, int port)
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress dst = InetAddress.getLocalHost(); int port = 8080; byte[] outbuf = new byte[1024]; int len = 1024; DatagramPacket request = new DatagramPacket(outbuf, len, dst, port); DatagramSocket socket = new DatagramSocket(); socket.send(request);/*from w w w .j a v a 2s. c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] outbuf = new byte[1024]; int port = 1234; DatagramSocket socket = new DatagramSocket(); InetAddress groupAddr = InetAddress.getByName("8.1.2.3"); DatagramPacket packet = new DatagramPacket(outbuf, outbuf.length, groupAddr, port); socket.send(packet);// w w w . jav a 2 s. c o m }
From source file:Main.java
public static void main(String args[]) { try {// w w w . j a v a 2s.c o m InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.setSoTimeout(1000); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/*from w w w .j av a 2 s. c om*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.setSendBufferSize(1000); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/* www.ja va2 s . c o m*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.setReuseAddress(true); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/*from w ww.java 2 s.co m*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.setBroadcast(true); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {// ww w. j a v a 2s. c om InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.setReceiveBufferSize(1000); ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/*from w w w . ja v a 2 s.com*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.send(dp); ds.disconnect(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/* w ww .java 2 s.c om*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); // Send the datagram packet ds.send(dp); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/* w w w. java2s. c o m*/ InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.send(dp); System.out.println(ds.isConnected()); } catch (Exception e) { e.printStackTrace(); } }