How can I find the response time of a HTTP request through a Socket

前端 未结 7 1524
猫巷女王i
猫巷女王i 2021-02-07 04:13

I\'m using a Java socket, connected to a server. If I send a HEADER http request, how can I measure the response time from the server? Must I use a provided java timer, or is t

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 04:19

    Maybe I'm missing something, but why don't you just use:

    // open your connection
    long start = System.currentTimeMillis();
    // send request, wait for response (the simple socket calls are all blocking)
    long end = System.currentTimeMillis();
    System.out.println("Round trip response time = " + (end-start) + " millis");
    

提交回复
热议问题