Example usage for java.net DatagramSocket getInetAddress

List of usage examples for java.net DatagramSocket getInetAddress

Introduction

In this page you can find the example usage for java.net DatagramSocket getInetAddress.

Prototype

public InetAddress getInetAddress() 

Source Link

Document

Returns the address to which this socket is connected.

Usage

From source file:Main.java

public static void main(String args[]) {
    try {//from   w  w w  .ja  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);

        // Send the datagram packet
        ds.send(dp);

        System.out.println(ds.getInetAddress());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.clustercontrol.poller.impl.UdpTransportMappingImpl.java

@Override
public UdpAddress getListenAddress() {
    UdpAddress actualListenAddress = null;
    DatagramSocket socketCopy = socket;
    if (socketCopy != null) {
        actualListenAddress = new UdpAddress(socketCopy.getInetAddress(), socketCopy.getLocalPort());
    }//from www.  ja  v a2  s . co m
    return actualListenAddress;
}