Advertisement
khatta_cornetto

2.java

Jan 30th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import java.net.*;
  2.  
  3. public class Example2SenderReceiver {
  4.     public static void main(String[] args) {
  5.         if (args.length != 4)
  6.             System.out.println("This program requires four command line arguments");
  7.         else {
  8.             try {
  9.                 InetAddress receiverHost = InetAddress.getByName(args[0]);
  10.                 int receiverPort = Integer.parseInt(args[1]);
  11.                 int myPort = Integer.parseInt(args[2]);
  12.                 String message = args[3];
  13.  
  14.                 MyDatagramSocket mySocket = new MyDatagramSocket(myPort);
  15.                 mySocket.sendMessage(receiverHost, receiverPort, message);
  16.                 System.out.println(mySocket.receiveMessage());
  17.                 mySocket.close();
  18.             } catch (Exception ex) {
  19.                 ex.printStackTrace();
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement