BomberStudentClient.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package rsx;
  7. import java.net.InetAddress;
  8. import java.util.ArrayList;
  9. import rsx.tcp.TcpClient;
  10. import rsx.udp.Broadcast;
  11. /**
  12. * Connexion à un server BomberStudent
  13. * @author Arthur Brandao
  14. */
  15. public class BomberStudentClient {
  16. protected int portUdp;
  17. protected int portTcp;
  18. protected Broadcast finder;
  19. protected TcpClient socket;
  20. /* --- Constructeurs --- */
  21. public BomberStudentClient(){
  22. this.portUdp = 28624;
  23. this.portTcp = 28642;
  24. this.finder = new Broadcast(this.portUdp);
  25. }
  26. public BomberStudentClient(int portUdp, int portTcp){
  27. this.portUdp = portUdp;
  28. this.portTcp = portTcp;
  29. this.finder = new Broadcast(this.portUdp);
  30. }
  31. /* --- Methodes --- */
  32. public int findServer(){
  33. this.finder.search("i'm a bomberstudent server");
  34. return this.finder.getServers().size();
  35. }
  36. public boolean selectServer(int index){
  37. ArrayList<InetAddress> serv = this.finder.getServers();
  38. if(index <= 0 || index >= serv.size()){
  39. System.err.println("Index invalide");
  40. return false;
  41. }
  42. this.socket = new TcpClient(this.finder.getServers().get(index), this.portTcp);
  43. return this.socket.connect();
  44. }
  45. public boolean send(String method, String ressource, String param){
  46. return false;
  47. }
  48. public BomberStudentReponse receive(){
  49. return null;
  50. }
  51. public boolean close(){
  52. return this.socket.close();
  53. }
  54. }