Skip to content

Commit

Permalink
Merge branch 'developer' of github.com:joaocarvoli/project-networkTra…
Browse files Browse the repository at this point in the history
…nsparency into developer
  • Loading branch information
joaocarvoli committed Jul 11, 2022
2 parents 449bb42 + eebc079 commit 6dee775
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
28 changes: 21 additions & 7 deletions client/client_Udp/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClientProxy{
public ClientProxy( String host, int portNumber ) {
try {
client = new ClientUDP(host, portNumber);
count = 1;
count = 0;

this.convert("USD", "BRL", (float) 5.068 );
this.currencyExists( "CAD" );
Expand Down Expand Up @@ -53,6 +53,8 @@ public float convert ( String fromCurrency, String toCurrency, float amount ){
args.add( "amount:" + Float.toString(amount) );
remoteObject.setArgments( args );
remoteObject.setMessageType( 0 );

// System.out.println( this.count );
remoteObject.setRequestId( this.count++ );

var responseObject = doOperation( remoteObject );
Expand All @@ -71,6 +73,8 @@ public boolean currencyExists ( String currency ) {
args.add("currency:" + currency);
remoteObject.setArgments( args );
remoteObject.setMessageType( 0 );

// System.out.println(this.count );
remoteObject.setRequestId( this.count++ );

var responseObject = doOperation( remoteObject );
Expand Down Expand Up @@ -112,13 +116,17 @@ public String getWheaterTemperature( String cityName ) {
List<String> args = new ArrayList<>();
args.add("city:" + cityName);
remoteObject.setArgments( args );
remoteObject.setMessageType( 0 );

// System.out.println( this.count );
remoteObject.setRequestId( this.count++ );


var responseObject = doOperation( remoteObject );
List<String> respArgs = responseObject.getArgments( );
String [] cityTemp = respArgs.get(0).split(":");
String answer = cityTemp[1];
System.out.println( answer );
// System.out.println( answer );
return answer;
}

Expand All @@ -129,13 +137,16 @@ public String getWheaterClouds( String cityName ) {
List<String> args = new ArrayList<>();
args.add("city:" + cityName);
remoteObject.setArgments( args );
remoteObject.setMessageType( 0 );
// System.out.println( this.count );
remoteObject.setRequestId( this.count++ );


var responseObject = doOperation( remoteObject );
List<String> respArgs = responseObject.getArgments( );
String [] cityClouds = respArgs.get(0).split(":");
String answer = cityClouds[1];
System.out.println( answer );
// System.out.println( answer );
return answer;
}

Expand All @@ -146,6 +157,9 @@ public String getWheaterWind( String cityName ) {
List<String> args = new ArrayList<>();
args.add("city:" + cityName);
remoteObject.setArgments( args );
remoteObject.setMessageType( 0 );
// System.out.println( this.count );
remoteObject.setRequestId( this.count++ );


var responseObject = doOperation( remoteObject );
Expand All @@ -165,7 +179,7 @@ public MessageObject doOperation( MessageObject objectMessage ) {
String responseJSON = client.getResponse( );
responseJSON = responseJSON.replace("\'", "\"");
responseJSON = responseJSON.replace(" ", "");
System.out.println("servidor retornou: " + responseJSON );
// System.out.println("servidor retornou: " + responseJSON );
var responseObj = unpackMessage( responseJSON );
return responseObj;
}
Expand Down Expand Up @@ -254,9 +268,9 @@ public void setRequestId(int requestId) {

}

public static void main (String[] args) {
ClientProxy prox = new ClientProxy("localhost", 7889);
// public static void main (String[] args) {
// ClientProxy prox = new ClientProxy("localhost", 7889);
//// ClientProxy prox = new ClientProxy("172.18.102.216", 7889 );
}
// }

}
69 changes: 53 additions & 16 deletions client/client_Udp/ClientUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,89 @@

public class ClientUser {

ClientProxy clientpx;
private ClientProxy clientpx;
int portNumber = 7889;


public ClientUser( String localhost ) {
this.clientpx = new ClientProxy(localhost, portNumber );
}

public void cotar(String texto ) {
float amount =0 ;
this.clientpx.convert("texto", "texto", amount);
}




public static void main (String[] args) {
Scanner scan = new Scanner( System.in );
System.out.println( "Informar endereço IP do servidor, localhost se for local:");
String host = scan.nextLine();

ClientUser client = new ClientUser( host);
ClientUser client = new ClientUser( host );
boolean done = false;

while( !done ) {
System.out.println(
"Cotar: Perguntar qual a cotação atual da moeda A -> B ( ex: USD : BRL : 5.068 )\n"
+ "Exist: Checar se uma determinada moeda existe na API ( ex: USD, CAD, AUS, BRL, BTC,...\n"
"Cotar: Perguntar qual a cotação atual da moeda A -> B ( ex: Cotar: USD : BRL : 5.068 )\n"
+ "Exist: Checar se uma determinada moeda existe na API ( ex: Exist: USD, Exist: CAD, Exist: AUS, Exist: BRL, Exist: BTC...)\n"
+ "List: Listar modeas disponíveis para consulta na API\n"
+ "Temp: Clouds: Wind: ");
+ "Temp: Checar a temperatura em uma cidade ( Fortaleza, Maracanaú... )\n"
+ "Clouds: Checar a nebulosidade em uma cidade ( Fortaleza, Maracanaú... )\n"
+ "Wind: Checar forçar dos ventos em uma cidade ( Fortaleza, Maracanaú... )" );
String line = scan.nextLine();
String [] lineSplitted = line.split(":");
// System.out.println( lineSplitted[1].toString() );

if( line.equals( "sair") ) {
if( lineSplitted[0].toLowerCase().equals( "sair") ) {
System.out.println("Encerrando...\n(-----------------------------)\"");
done = true;
}
if( line .equals("Cotar" ) ) {
else if( lineSplitted[0].toLowerCase().equals("cotar" ) ) {
String ask1 = lineSplitted[1].toUpperCase();
ask1 = ask1.replace(" ", "");
System.out.println(ask1);
String ask2 = lineSplitted[2].toUpperCase();
ask2 = ask2.replace(" ", "");
System.out.println(ask2);

float amount = Float.parseFloat(lineSplitted[3]);
float result = client.clientpx.convert(ask1, ask2, amount);
System.out.println("O valor convertido é: " + result + "\n(-----------------------------)");
}
if( line .equals("Exist" ) ) {
else if( lineSplitted[0].toLowerCase().equals("exist" ) ) {
String ask = lineSplitted[1].toUpperCase();
ask = ask.replace(" ", "");
System.out.println(ask);
boolean result = client.clientpx.currencyExists(ask);
if( !result ) {
System.out.println("Desculpe, não foi encontrado nada sobre " + ask + "\n(-----------------------------)");
} else {
System.out.println("Sim, " + ask + " é uma das moedas reconhecidas pela aplicação :D\n(-----------------------------)");
}

}
if( line .equals("List" ) ) {

else if( lineSplitted[0].toLowerCase().equals("list" ) ) {
System.out.println("Desculpa, função ainda precisa de ajustes...\n(-----------------------------)\"");
}
if( line .equals("Temp" ) ) {

else if( lineSplitted[0].toLowerCase().equals("temp" ) ) {
String ask = lineSplitted[1].toLowerCase();
String result = client.clientpx.getWheaterTemperature( ask );
System.out.println(lineSplitted[1].toString() + " está a " + result + " graus\n(-----------------------------)" );
}
if( line .equals("Clouds" ) ) {

else if( lineSplitted[0].toLowerCase().equals("clouds" ) ) {
String ask = lineSplitted[1].toLowerCase();
String result = client.clientpx.getWheaterClouds( ask );
System.out.println( "As nuvens em " + lineSplitted[1].toString() + " estão " + result + "\n(-----------------------------)");
}
if( line .equals("Wind" ) ) {

else if( lineSplitted[0].toLowerCase().equals("wind" ) ) {
String ask = lineSplitted[1].toLowerCase();
String result = client.clientpx.getWheaterWind( ask );
System.out.println("Os ventos em " + lineSplitted[1].toString() + " estão a " + result + " nós\n(-----------------------------)" );
}else {
System.out.println("Desculpe, comando fora dos padrões reconhecidos\n(-----------------------------)");
}
}

Expand Down

0 comments on commit 6dee775

Please sign in to comment.