Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package com.udp;
  2. import java.io.IOException;
  3. import java.net.*;
  4.  
  5.  
  6.  
  7. public class Server{
  8.  
  9. private DatagramSocket socket;
  10. private byte[] buf = new byte[256];
  11.  
  12. public static void main(String[] args) throws IOException{
  13.  
  14.  
  15. if(args.length != 1) {
  16. System.out.println("Error calling method");
  17. return;
  18. }
  19.  
  20. new Server().run(Integer.parseInt(args[0]));
  21.  
  22. }
  23.  
  24. public void run(int port) throws IOException {
  25.  
  26. boolean running = true;
  27. socket = new DatagramSocket(port);
  28.  
  29. while(running) {
  30. DatagramPacket packet = new DatagramPacket(buf, 256);
  31. socket.receive(packet);
  32.  
  33. }
  34.  
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement