Advertisement
Josif_tepe

Untitled

Apr 23rd, 2021
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.net.*;
  2. import java.sql.SQLSyntaxErrorException;
  3. import java.util.Scanner;
  4.  
  5. public class Client {
  6.  
  7.     public static void main(String[] args) {
  8.         try {
  9.             Scanner sc = new Scanner(System.in);
  10.             DatagramSocket datagramSocket = new DatagramSocket();
  11.             InetAddress ip = InetAddress.getLocalHost();
  12.             byte[] b = null;
  13.             while(true) {
  14.                 String s = sc.nextLine();
  15.                 b = s.getBytes();
  16.                 DatagramPacket send_message = new DatagramPacket(b, b.length, ip, 4567);
  17.                 datagramSocket.send(send_message);
  18.                 if(s.equals("END") == true) {
  19.                     System.out.println("ENDING");
  20.                     break;
  21.                 }
  22.             }
  23.         }
  24.         catch (Exception ex) {
  25.             ex.printStackTrace();
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement