Example usage for java.net DatagramSocket getPort

List of usage examples for java.net DatagramSocket getPort

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Returns the port number to which this socket is connected.

Usage

From source file:Main.java

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

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

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