31 lines
1.0 KiB
Java
31 lines
1.0 KiB
Java
package fr.istic.grpc.echo;
|
|
|
|
import com.google.rpc.context.AttributeContext.*;
|
|
import fr.istic.grpc.echo.Echo.*;
|
|
import fr.istic.grpc.echo.EchoServiceGrpc.*;
|
|
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();
|
|
}
|
|
|
|
}
|