Przeglądaj źródła

Fin class BomberStudentClient

Arthur Brandao 6 lat temu
rodzic
commit
5cff5e1c4d
1 zmienionych plików z 21 dodań i 3 usunięć
  1. 21 3
      Client/rsx/BomberStudentClient.java

+ 21 - 3
Client/rsx/BomberStudentClient.java

@@ -7,6 +7,7 @@ package rsx;
 
 import java.net.InetAddress;
 import java.util.ArrayList;
+import org.json.JSONObject;
 import rsx.tcp.TcpClient;
 import rsx.udp.Broadcast;
 
@@ -52,12 +53,29 @@ public class BomberStudentClient {
         return this.socket.connect();
     }
     
-    public boolean send(String method, String ressource, String param){
-        return false;
+    public boolean send(String method, String ressource, JSONObject param){
+        //Verif que la methode existe
+        method = method.toUpperCase();
+        if(!method.equals("POST") && !method.equals("GET")){
+            return false;
+        }
+        //Creation json pour envoi
+        JSONObject json = new JSONObject();
+        json.put("methode", method);
+        json.put("ressource", ressource);
+        json.put("param", param);
+        //Envoi
+        this.socket.send(json.toString());
+        return true;
     }
     
     public BomberStudentReponse receive(){
-        return null;
+        String msg = this.socket.receive();
+        if(msg == null){
+            return new BomberStudentReponse();
+        } else {
+            return new BomberStudentReponse(msg);
+        }
     }
     
     public boolean close(){