|  | @@ -18,18 +18,43 @@ import rsx.udp.Broadcast;
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  public class BomberStudentClient {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Port pour le boradcast UDP
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      protected int portUdp;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Port pour la socket TCP
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      protected int portTcp;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Class pour broadcast
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      protected Broadcast finder;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Class pour le client TCP
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      protected TcpClient socket;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /* --- Constructeurs --- */
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Creation d'un client BomberStudent
 | 
	
		
			
				|  |  | +     * Le port 18624 est utilisé pour le broadcast udp
 | 
	
		
			
				|  |  | +     * Le port 18642 est utilisé pour la socket TCP
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public BomberStudentClient() {
 | 
	
		
			
				|  |  |          this.portUdp = 18624;
 | 
	
		
			
				|  |  |          this.portTcp = 18642;
 | 
	
		
			
				|  |  |          this.finder = new Broadcast(this.portUdp);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Creation d'un client BomberStudent
 | 
	
		
			
				|  |  | +     * @param portUdp Le port pour le broadcast UDP
 | 
	
		
			
				|  |  | +     * @param portTcp Le port pour la socket TCP
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public BomberStudentClient(int portUdp, int portTcp) {
 | 
	
		
			
				|  |  |          this.portUdp = portUdp;
 | 
	
		
			
				|  |  |          this.portTcp = portTcp;
 | 
	
	
		
			
				|  | @@ -37,11 +62,20 @@ public class BomberStudentClient {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /* --- Methodes --- */
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Cherche un serveur par broadcast
 | 
	
		
			
				|  |  | +     * @return Le nombre de serveur trouvé
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public int findServer() {
 | 
	
		
			
				|  |  |          this.finder.search("i'm a bomberstudent server");
 | 
	
		
			
				|  |  |          return this.finder.getServers().size();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Selectionne un serveur pour s'y connecter
 | 
	
		
			
				|  |  | +     * @param index Le numero du serveur dans la liste
 | 
	
		
			
				|  |  | +     * @return Reussite
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public boolean selectServer(int index) {
 | 
	
		
			
				|  |  |          ArrayList<InetAddress> serv = this.finder.getServers();
 | 
	
		
			
				|  |  |          System.out.println(serv.size());
 | 
	
	
		
			
				|  | @@ -53,10 +87,23 @@ public class BomberStudentClient {
 | 
	
		
			
				|  |  |          return this.socket.connect();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Envoi requete sur le serveur
 | 
	
		
			
				|  |  | +     * @param method Methode d'envoi (POST ou GET)
 | 
	
		
			
				|  |  | +     * @param ressource Ressource demandée
 | 
	
		
			
				|  |  | +     * @return Reussite
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public boolean send(String method, String ressource) {
 | 
	
		
			
				|  |  |          return this.send(method, ressource, null);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Envoi requete sur le serveur
 | 
	
		
			
				|  |  | +     * @param method Methode d'envoi (POST ou GET)
 | 
	
		
			
				|  |  | +     * @param ressource Ressource demandée
 | 
	
		
			
				|  |  | +     * @param param Parametre JSON à envoyer au serveur
 | 
	
		
			
				|  |  | +     * @return Reussite
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public boolean send(String method, String ressource, JSONObject param) {
 | 
	
		
			
				|  |  |          //Verif que la methode existe
 | 
	
		
			
				|  |  |          method = method.toUpperCase();
 | 
	
	
		
			
				|  | @@ -75,6 +122,10 @@ public class BomberStudentClient {
 | 
	
		
			
				|  |  |          return true;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Attend une reponse du serveur
 | 
	
		
			
				|  |  | +     * @return La reponse analysée
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public BomberStudentReponse receive() {
 | 
	
		
			
				|  |  |          String msg = this.socket.receive();
 | 
	
		
			
				|  |  |          if (msg == null) {
 | 
	
	
		
			
				|  | @@ -84,6 +135,10 @@ public class BomberStudentClient {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * Ferme la connexion
 | 
	
		
			
				|  |  | +     * @return Reussite
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      public boolean close() {
 | 
	
		
			
				|  |  |          return this.socket.close();
 | 
	
		
			
				|  |  |      }
 |