12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*
- * 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();
- }
-
- }
|