Procházet zdrojové kódy

:tada: Ajout class gestion serveur bomberstudent

Arthur Brandao před 6 roky
rodič
revize
f30160d0c5

+ 67 - 0
Client/rsx/BomberStudentClient.java

@@ -0,0 +1,67 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package rsx;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import rsx.tcp.TcpClient;
+import rsx.udp.Broadcast;
+
+/**
+ * Connexion à un server BomberStudent
+ * @author Arthur Brandao
+ */
+public class BomberStudentClient {
+    
+    protected int portUdp;
+    protected int portTcp;
+    protected Broadcast finder;
+    protected TcpClient socket;
+    
+    /* --- Constructeurs --- */
+    
+    public BomberStudentClient(){
+        this.portUdp = 28624;
+        this.portTcp = 28642;
+        this.finder = new Broadcast(this.portUdp);
+    }
+    
+    public BomberStudentClient(int portUdp, int portTcp){
+        this.portUdp = portUdp;
+        this.portTcp = portTcp;
+        this.finder = new Broadcast(this.portUdp);
+    }
+    
+    /* --- Methodes --- */
+    
+    public int findServer(){
+        this.finder.search("i'm a bomberstudent server");
+        return this.finder.getServers().size();
+    }
+    
+    public boolean selectServer(int index){
+        ArrayList<InetAddress> serv = this.finder.getServers();
+        if(index <= 0 || index >= serv.size()){
+            System.err.println("Index invalide");
+            return false;
+        }
+        this.socket = new TcpClient(this.finder.getServers().get(index), this.portTcp);
+        return this.socket.connect();
+    }
+    
+    public boolean send(String method, String ressource, String param){
+        return false;
+    }
+    
+    public BomberStudentReponse receive(){
+        return null;
+    }
+    
+    public boolean close(){
+        return this.socket.close();
+    }
+    
+}

+ 9 - 0
Client/rsx/BomberStudentReponse.java

@@ -0,0 +1,9 @@
+package rsx;
+
+/**
+ * Analyse reponse d'un serveur BomberStudent
+ * @author Arthur Brandao
+ */
+public class BomberStudentReponse {
+    
+}

+ 25 - 5
Client/rsx/tcp/TcpClient.java

@@ -19,11 +19,11 @@ import java.net.UnknownHostException;
  */
 public class TcpClient {
     
-    private InetAddress adr;
-    private int port;
-    private Socket socket;
-    private BufferedReader input;
-    private DataOutputStream output;
+    protected InetAddress adr;
+    protected int port;
+    protected Socket socket;
+    protected BufferedReader input;
+    protected DataOutputStream output;
     
     /* --- Constructeurs --- */
     
@@ -83,4 +83,24 @@ public class TcpClient {
         return true;
     }
     
+    /* --- Getter/Setter --- */
+
+    public InetAddress getAdr() {
+        return adr;
+    }
+
+    public void setAdr(InetAddress adr) {
+        this.adr = adr;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+    
+    
+    
 }