This commit is contained in:
trochas
2025-04-01 16:03:40 +02:00
parent ce684107c5
commit 46dbc9e4ce
3 changed files with 35 additions and 2 deletions

View File

@@ -7,5 +7,24 @@ import io.grpc.*;
public class EchoClient {
public static void main(String[] args) throws Exception {
ManagedChannel channel = ManagedChannelBuilder
.forAddress("localhost", 8080) //serveur localhost, port 8080
.usePlaintext() // on demande a ne pas utiliser tls
.build(); // pattern builder
//On utilise un stub bloquant pour faire la requête (on bloque jusqu'à réponse)
EchoServiceGrpc.EchoServiceBlockingStub stub = EchoServiceGrpc.newBlockingStub(channel);
//On construit la requête :
MessageSent request = MessageSent.newBuilder().setMessage("ilililili").build();
// On appelle le serveur :
MessageReceive response = stub.echo(request);
// On affiche le résultat
System.out.println("Reçu : " + response.getMessage());
channel.shutdown();
}
}