java - SSLSocket client's input stream could not recieve anything from server -


i'm trying make tls client send request https server. however, there no input server when tries send request second time , more. can't why skipping other responses.

client code:

public class main {  private static final string host = "testserver.com"; private static final int port = 443;  public static void main(string[] args) throws ioexception {     bufferedreader socketreader;     printwriter socketwriter;      sslsocketfactory sslsocketfactory = (sslsocketfactory) sslsocketfactory.getdefault();     sslsocket sslsocket = (sslsocket) sslsocketfactory.createsocket(host, port);     sslsocket.setkeepalive(true);     sslsocket.setuseclientmode(true);     sslsocket.setenabledprotocols(new string[] { "tlsv1.2" });     sslsocket.setenabledciphersuites(new string[] { "tls_rsa_with_aes_128_cbc_sha" });     sslsocket.starthandshake();      socketwriter = new printwriter(new bufferedwriter(new outputstreamwriter(sslsocket.getoutputstream())));     socketreader = new bufferedreader(new inputstreamreader(sslsocket.getinputstream()));      while (true) {         socketwriter.print("get / http/1.0\r\n");         socketwriter.print("accept: text/plain, text/html, text/*\r\n");         socketwriter.print("\r\n");         socketwriter.flush();          string inputline;         while ((inputline = socketreader.readline()) != null) {             system.out.println(inputline);         }          system.out.println("finished sending request");     }  } 

output example:

http/1.1 200 ok server: nginx/1.10.1 date: thu, 06 apr 2017 15:37:21 gmt content-type: text/html content-length: 110 last-modified: fri, 31 mar 2017 19:19:44 gmt connection: close vary: accept-encoding etag: "58deabd0-6e" accept-ranges: bytes <html> <head>     <title>test server</title> </head> <body>     test </body> </html> finished sending request  finished sending request  finished sending request  finished sending request 

that's because http connection not persistent (note connection: close header in response). need either add connection: keep-alive header request or switch http 1.1 (connections persistent default). otherwise you'll have create new tcp connection each request.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -