Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;

public class Main {

    public static void main(String args[]) {
        try {

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