Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4.  
  5. public class DatagramClient {
  6.  
  7. public static void main(String[] args) throws IOException {
  8.  
  9. InetAddress adresa = InetAddress.getByName("127.0.0.1");
  10. int port = 8200;
  11. DatagramSocket socket = null;
  12. DatagramPacket packet = null;
  13. byte buf[];
  14. try {
  15. socket = new DatagramSocket();
  16. buf = " Craiova ".getBytes();
  17. packet = new DatagramPacket(buf, buf.length, adresa, port);
  18. socket.send(packet);
  19. buf = new byte[256];
  20. packet = new DatagramPacket(buf, buf.length);
  21. socket.receive(packet);
  22. System.out.println(new String(packet.getData()));
  23. } finally {
  24. if (socket != null)
  25. socket.close();
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement