Example usage for java.net InetAddress getByName

List of usage examples for java.net InetAddress getByName

Introduction

In this page you can find the example usage for java.net InetAddress getByName.

Prototype

public static InetAddress getByName(String host) throws UnknownHostException 

Source Link

Document

Determines the IP address of a host, given the host's name.

Usage

From source file:Main.java

public static void main(String args[]) {
    try {//ww  w .  j a  va  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.bind(InetSocketAddress.createUnresolved("google.com", 8080));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {/*from w  ww.  j  av a 2s  .  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.connect(InetSocketAddress.createUnresolved("google.com", 80));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {/*from www.j  a  va2s .  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.connect(InetSocketAddress.createUnresolved("google.com", 8080));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:MainClass.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();
    ms.joinGroup(ia);/*from  ww  w  .ja  v a2 s. c o m*/
    for (int i = 1; i < 10; i++) {
        ms.send(dp, ttl);
    }
    ms.leaveGroup(ia);
    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();
    ms.joinGroup(ia);//w  w w. ja v  a 2s .  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) 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(8080);
    ms.joinGroup(ia);//  w ww. ja v a2 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:MainClass.java

public static void main(String[] args) throws Exception {
    InetAddress server = InetAddress.getByName("localhost");
    BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
    DatagramSocket theSocket = new DatagramSocket();
    while (true) {
        String theLine = userInput.readLine();
        if (theLine.equals("."))
            break;
        byte[] data = theLine.getBytes();
        DatagramPacket theOutput = new DatagramPacket(data, data.length, server, 99999);
        theSocket.send(theOutput);/*from w w w.j  a  v a2s .c  om*/
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InetAddress address = null;/*from   ww  w  .  jav a 2s.  c om*/
    if (args.length == 0) {
        System.out.println("usage: GetIP host");
        System.exit(1);
    }

    address = InetAddress.getByName(args[0]);
    System.out.println(address.getHostName() + "=" + address.getHostAddress());
    System.exit(0);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    String groupName = "groupName";
    int port = 1024;
    MulticastSocket msocket = new MulticastSocket(port);
    InetAddress group = InetAddress.getByName(groupName);
    msocket.joinGroup(group);//from   w ww .j ava2s. c  o  m

}

From source file:Main.java

public static void main(String args[]) {
    try {/* w w w  .java 2s.  com*/

        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();
    }
}