You are on page 1of 1

import java.io.

IOException;
import java.net.*;
import java.util.Scanner;

public class SocketDatagrama_EmisorUDP_PazAbedoyChristian{


public static void main (String [] args) {
Scanner in = new Scanner(System.in);
try {
InetAddress receptor = InetAddress.getByName("localhost");
DatagramSocket socketEmisor = new DatagramSocket();
System.out.println("Teclee el mensaje: ");
String mensaje = in.nextLine();
byte[] bufferEmisor = mensaje.getBytes();
DatagramPacket datagramaEmisor = new DatagramPacket(bufferEmisor,
bufferEmisor.length, receptor, 45982);
socketEmisor.send(datagramaEmisor);
} catch (SocketException e) {
System.out.println("Excepcion Socket:" + e.getMessage());
} catch (IOException e) {
System.out.println("Excepcion IO:" + e.getMessage());
}
}
}

You might also like