0
我有android客戶端和C++服務器,並且工作在ssl(TLS)連接。但對於每一條消息,我都必須打開新的SSL會話等。 我可以通過一個ssl套接字發送多封郵件嗎?怎麼樣? 我試過重複使用我的單消息工作代碼,如下所示。Android:通過sslsocket連接發送多個消息
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(sslSocket.getOutputStream()));
w.write(request, 0, request.length());
w.flush(); // this works (server got data)
BufferedReader r = new BufferedReader(new InputStreamReader(sslSocket.getInputStream()));
StringBuilder response = new StringBuilder();
String actRecieved = null;
while ((actRecieved = r.readLine()) != null) {
response.append(actRecieved);
}
Log.d("TEST", "one: " + response.toString()); // this works (server send data, I read it)
request = "some special request 2";
w.write(request, 0, request.length());
w.flush(); // this does not work, no data went to server, but no error occured
actRecieved = null;
response = new StringBuilder();
while ((actRecieved = r.readLine()) != null) {
response.append(actRecieved);
}
Log.d("TEST", "two: " + response.toString()); // this does not work as well, because server is not send any data
那麼,問題在哪裏呢?誰能告訴我?
更新
我剛剛發現了2個寫入請求將達到服務器的時候,我不從流中讀取。
從一個套接字使用輸入和輸出流多重時間有沒有問題? 我應該使用兩個套接字 - 一個用於讀取,一個用於寫入?
幫助任何人。