Created
June 20, 2021 08:02
-
-
Save ruan65/7c0f99bffccb5b675b87bffe6e3a8dad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:grpc/grpc.dart'; | |
import 'generated/umka.pbgrpc.dart'; | |
class UmkaTerminalClient { | |
late final ClientChannel channel; | |
late final UmkaClient stub; | |
UmkaTerminalClient() { | |
channel = ClientChannel( | |
'127.0.0.1', | |
port: 5555, | |
options: ChannelOptions(credentials: ChannelCredentials.insecure()), | |
); | |
stub = UmkaClient(channel); | |
} | |
Future<Question> getQuestion(Student student) async { | |
final question = await stub.getQuestion(student); | |
print('Received question: $question'); | |
return question; | |
} | |
Future<void> sendAnswer(Student student, Question question) async { | |
final answer = Answer() | |
..question = question | |
..student = student; | |
print('Enter your answer: '); | |
answer.text = stdin.readLineSync()!; | |
final evaluation = await stub.sendAnswer(answer); | |
print('Evaluation for the answer: ${answer.text} ' | |
'\non the question ${question.text}:' | |
'\n$evaluation'); | |
} | |
Future<void> callService(Student student) async { | |
final question = await getQuestion(student); | |
await sendAnswer(student, question); | |
await channel.shutdown(); | |
} | |
} | |
Future<void> main(List<String> args) async { | |
final clientApp = UmkaTerminalClient(); | |
final student = Student() | |
..id = 42 | |
..name = 'Alice Bobich'; | |
await clientApp.callService(student); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment