Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1.  
  2. import java.io.IOException;
  3. import java.net.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class Server implements Runnable {
  8.  
  9. ArrayList<Integer> portslist = new ArrayList<>();
  10. private byte[] buf = new byte[256];
  11. DatagramSocket socket;
  12.  
  13. public Server(ArrayList<Integer> portslist) {
  14.  
  15. this.portslist = portslist;
  16.  
  17. }
  18.  
  19. public static void main(String args[]) throws IOException {
  20.  
  21. if ((args[0]).matches("\\d*")) {
  22. System.out.println("hura");
  23. }
  24.  
  25. else {
  26. System.out.println("You can start program using ListOfPorts");
  27. }
  28.  
  29. }
  30.  
  31. @Override
  32. public void run() {
  33.  
  34. while(true) {
  35.  
  36. try {
  37. socket = new DatagramSocket(2);
  38. } catch (SocketException e) {
  39.  
  40. e.printStackTrace();
  41. }
  42.  
  43. DatagramPacket packet = new DatagramPacket(buf, buf.length);
  44. try {
  45. socket.receive(packet);
  46. } catch (IOException e) {
  47.  
  48. e.printStackTrace();
  49. }
  50.  
  51. InetAddress address = packet.getAddress();
  52. int port = packet.getPort();
  53. packet = new DatagramPacket(buf, buf.length, address, port);
  54. String received = new String(packet.getData(), 0, packet.getLength());
  55.  
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement