packagebidirectional;importcom.example.grpc.BidirectionalServiceGrpc.*;importcom.example.grpc.BidirectionalServiceOuterClass.*;importio.grpc.stub.StreamObserver;publicclassBidirectionalServiceImplextendsBidirectionalServiceImplBase{@OverridepublicStreamObserver<ClientRequest>bidirectional(StreamObserver<ServerResponse>responseObserver){//it returns the stream that will be used by the clients to send messages. The client will write on this streamreturnnewStreamObserver<ClientRequest>(){//receiving a message from the clientpublicvoidonNext(ClientRequestclientRequest){StringclientStringRequest=clientRequest.getStringRequest();System.out.println("[FROM CLIENT] "+clientStringRequest);// sending the response to the clientSystem.out.println("Sending the response to the client...\n");responseObserver.onNext(ServerResponse.newBuilder().setStringResponse("I've received this message: '"+clientStringRequest+"'").build());}publicvoidonError(Throwablethrowable){}publicvoidonCompleted(){}};}}