search

Home  >  Q&A  >  body text

Java中Http和Socket是什么关系?

Java中Http和Socket是什么关系?

黄舟黄舟2887 days ago369

reply all(4)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:28:59

    1. First of all, there is a problem with the statement that socket is a long connection. Socket is an intermediate software abstraction layer for communication between the application layer and the TCP/IP protocol family. It can use either the underlying TCP or UDP. Http is based on TCP. The long connections and short connections of the HTTP protocol are essentially the long connections and short connections of the TCP protocol.

    2. Long connections and short connections are relative.
      Long connection: After establishing a connection, it is maintained for a period of time. During this period, multiple requests and responses use this connection.
      Short connection: Each time a request is made, a connection is established, and the connection is closed when the server responds.

    3. HTTP/1.0 is a short connection, HTTP/1.1 supports long connections, and HTTP/2 has been improved. What is the need behind these improvements? Recommended history of HTTP

    reply
    0
  • PHPz

    PHPz2017-04-18 10:28:59

    To be precise, HTTP is based on TCP/IP.

    TCP/IP can be long or short, while HTTP mainly uses it as short.

    HTTP can also be long, as long as the server and browser do not close the link all the time. This method was once popular to achieve real-time server notification (search http comet to find out).

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:28:59

    HTTP just "does not require" long connections. You can keep it alive or close the socket immediately after the transmission is completed. There is no problem.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:28:59

    Before asking [why], please research clearly [whether it is]!

    reply
    0
  • Cancelreply