Advertisement
Josif_tepe

Untitled

Mar 31st, 2022
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.DatagramPacket;
  3. import java.net.DatagramSocket;
  4. import java.net.InetAddress;
  5. import java.net.Socket;
  6. import java.util.Scanner;
  7. import java.util.concurrent.*;
  8.  
  9. public class Client {
  10.     public static void main(String[] args) {
  11.         try {
  12.             DatagramSocket datagramSocket = new DatagramSocket();
  13.             Scanner sc = new Scanner(System.in);
  14.             InetAddress ip = InetAddress.getLocalHost();
  15.             byte[] b = null;
  16.             while(true) {
  17.                 String s = sc.nextLine();
  18.                 b = s.getBytes();
  19.                 DatagramPacket send_message = new DatagramPacket(b, b.length, ip, 1234);
  20.                 datagramSocket.send(send_message);
  21.                 if (s.equals("END")) {
  22.                     break;
  23.                 }
  24.  
  25.             }
  26.         }
  27.         catch (IOException i) {
  28.             i.printStackTrace();
  29.         }
  30.     }
  31.  
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement