List of usage examples for java.net InetSocketAddress createUnresolved
public static InetSocketAddress createUnresolved(String host, int port)
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("google.com"), port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("google.com", 8080)); ms.joinGroup(InetSocketAddress.createUnresolved("127.0.0.1", 8080), NetworkInterface.getByIndex(0)); for (int i = 1; i < 10; i++) { ms.send(dp, ttl);//ww w .java 2s. c o m } ms.setNetworkInterface(NetworkInterface.getByIndex(0)); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("google.com"), port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("google.com", 8080)); ms.joinGroup(InetSocketAddress.createUnresolved("127.0.0.1", 8080), NetworkInterface.getByIndex(0)); for (int i = 1; i < 10; i++) { ms.send(dp, ttl);//from w w w.j ava 2 s .co m } ms.setTimeToLive(1000); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("google.com"), port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("google.com", 8080)); ms.joinGroup(InetSocketAddress.createUnresolved("127.0.0.1", 8080), NetworkInterface.getByIndex(0)); for (int i = 1; i < 10; i++) { ms.send(dp, ttl);//www . j a va 2 s . c om } ms.leaveGroup(InetSocketAddress.createUnresolved("java2s.com", 8080), NetworkInterface.getByIndex(0)); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, InetAddress.getByName("google.com"), port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("google.com", 8080)); ms.joinGroup(InetSocketAddress.createUnresolved("127.0.0.1", 8080), NetworkInterface.getByIndex(0)); for (int i = 1; i < 10; i++) { ms.send(dp, ttl);/*from w w w . j a va 2s . co m*/ } ms.setInterface(InetAddress.getByName("google.com")); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; InetAddress ia = InetAddress.getByName("127.0.0.1"); byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("java2s.com", 8080)); ms.joinGroup(ia);/*from w w w . j a v a 2 s . co m*/ for (int i = 1; i < 10; i++) { ms.send(dp, ttl); } ms.leaveGroup(ia); System.out.println(ms.getTimeToLive()); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; InetAddress ia = InetAddress.getByName("127.0.0.1"); byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("java2s.com", 8080)); ms.joinGroup(ia);//from ww w. j a v a 2 s. c om for (int i = 1; i < 10; i++) { ms.send(dp, ttl); } ms.leaveGroup(ia); System.out.println(ms.getLoopbackMode()); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; InetAddress ia = InetAddress.getByName("127.0.0.1"); byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("java2s.com", 8080)); ms.joinGroup(ia);//from ww w.j a v a2 s . co m for (int i = 1; i < 10; i++) { ms.send(dp, ttl); } ms.leaveGroup(ia); System.out.println(ms.getNetworkInterface().getDisplayName()); ms.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { int port = 0; byte ttl = (byte) 1; InetAddress ia = InetAddress.getByName("127.0.0.1"); byte[] data = "Here's some multicast data\r\n".getBytes(); DatagramPacket dp = new DatagramPacket(data, data.length, ia, port); MulticastSocket ms = new MulticastSocket(InetSocketAddress.createUnresolved("java2s.com", 8080)); ms.joinGroup(ia);/*from w ww . j a v a 2 s . co m*/ for (int i = 1; i < 10; i++) { ms.send(dp, ttl); } ms.leaveGroup(ia); ia = ms.getInterface(); System.out.println(ia); ms.close(); }
From source file:Main.java
public static void main(String args[]) { try {//from w ww. j ava 2 s .c om InetAddress ia = InetAddress.getByName("www.java2s.com"); DatagramSocket ds = new DatagramSocket(8080, ia); byte buffer[] = "hello".getBytes(); DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80); ds.connect(InetSocketAddress.createUnresolved("google.com", 8080)); DatagramChannel channel = ds.getChannel(); ds.send(dp); ds.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {//from w w w . jav a 2 s . c o m int port = 80; DatagramSocket ds = new DatagramSocket(port); byte buffer[] = new byte[BUFSIZE]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); // Receive data ds.receive(dp); // Display address from the datagram packet InetAddress ia = dp.getAddress(); System.out.println(ia); dp.setSocketAddress(InetSocketAddress.createUnresolved("google.com", 8080)); } } catch (Exception e) { e.printStackTrace(); } }