Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public void povoarBack_end() {
  2. ServerDescription s =new ServerDescription();
  3. ServerDescription s1=new ServerDescription();
  4. ServerDescription s2=new ServerDescription();
  5.  
  6. this.DESTINATION_HOST[0]=s;
  7.  
  8. try {
  9. s.monitorUDP=new MonitorUDP(this.getDatagramSocket(),s.getSocket(),s.getId());// é aqui que pára
  10. } catch (SocketException e) {
  11. e.printStackTrace();
  12. }
  13. System.out.println("Teste");
  14. s.monitorUDP.run();
  15. this.DESTINATION_HOST[1]=s1;
  16. try {
  17. s1.monitorUDP=new MonitorUDP(this.getDatagramSocket(),s1.getSocket(),s1.getId());
  18. } catch (SocketException e) {
  19. e.printStackTrace();
  20. }
  21. System.out.println("Teste");
  22. s1.monitorUDP.run();
  23. this.DESTINATION_HOST[2]=s2;
  24. try {
  25. s2.monitorUDP=new MonitorUDP(this.getDatagramSocket(),s2.getSocket(),s2.getId());
  26. } catch (SocketException e) {
  27. e.printStackTrace();
  28. }
  29. System.out.println("Teste");
  30. s2.monitorUDP.run();
  31. System.out.println("Fim");
  32. }
  33.  
  34. public class MonitorUDP extends TimerTask implements Runnable {
  35.  
  36. private static DatagramSocket datagramSocket = null;
  37. private static final int port = 5555;
  38. public String address;
  39. public Socket s;
  40. public DatagramSocket fwdS;
  41. Timer timer;
  42. private final int id;
  43.  
  44. public MonitorUDP(DatagramSocket fwS,Socket s,int id) throws SocketException {
  45. this.address=s.getInetAddress().toString();
  46. this.fwdS=fwS;
  47. this.s=s;
  48. this.id=id;
  49. }
  50. @Override
  51. public void run() {
  52.  
  53. timer = new Timer();
  54. timer.schedule(new Task_Monitor(fwdS,s,id),1000);
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement