我一直在使用Bidirectional Streaming的概念Grpc使用Async stub。以下是我的代碼@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnOnline = (Button) findViewById(R.id.btnOnline); btnOffline = (Button) findViewById(R.id.btnOffline); btnAcceptRide = (Button) findViewById(R.id.btnAcceptRide); btnCancelRide = (Button) findViewById(R.id.btnCancelRide); txtCode = (EditText) findViewById(R.id.txtCode); txtReply = (TextView) findViewById(R.id.txtReply); ClientConnState = 0; btnOnline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new GrpcTask().execute(); } }); private class GrpcTask extends AsyncTask<Void, Void, String> { private String mHost; private String mMessage; private int mPort; private ManagedChannel mChannel; @Override protected void onPreExecute() { mHost = "localhost"; mPort = 8080; mChannel = ManagedChannelBuilder.forAddress("192.168.0.102", 50049) .usePlaintext(true) .build(); blockingStub = bidirectionalserviceGrpc.newBlockingStub(mChannel); asyncStub = bidirectionalserviceGrpc.newStub(mChannel); } @Override protected String doInBackground(Void... nothing) { try { final CountDownLatch countDownLatch = new CountDownLatch(1); requestStreamObserver = asyncStub.requestRide(new StreamObserver<Bidirectional.RideReply>() { @Override public void onNext(Bidirectional.RideReply value) { if (countDownLatch.getCount() > 0) { countDownLatch.countDown(); } }現在一切正常..我可以使用建立的流來ping/pong服務器/客戶端。但是當我關閉服務器并從客戶端發出流請求時,它會等待無窮大。我除了它拋出OnError()事件,但它沒有。有人可以幫我解決這個問題嗎?
添加回答
舉報
0/150
提交
取消