Advertisement
Guest User

Untitled

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