Example usage for java.net DatagramSocket getRemoteSocketAddress

List of usage examples for java.net DatagramSocket getRemoteSocketAddress

Introduction

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

Prototype

public SocketAddress getRemoteSocketAddress() 

Source Link

Document

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

Usage

From source file:Main.java

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

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

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

From source file:org.restcomm.sbc.media.MediaZone.java

private String toPrint(DatagramSocket socket) {
    return "Socket Bound to " + socket.getLocalSocketAddress() + " Connected to "
            + socket.getRemoteSocketAddress();
}