Java's HttpServletResponse doesn't have isClientConnected method

后端 未结 2 1600
挽巷
挽巷 2021-01-12 09:10

I\'m implementing a long poll http connection using java servlet.

How can I know that the http client is still active at any instance? Currently, what I do is to wri

相关标签:
2条回答
  • 2021-01-12 09:12

    Maybe you've taken the wrong approach? HTTP protocol is developed to be used in a request-response style, it is not suited to be used for a long polling. In fact, there should be lowest possible delay before client gets a server response.

    The case you've described looks like a job for a good old Socket.

    0 讨论(0)
  • 2021-01-12 09:35

    It will be difficult to achieve that using Servlet APIs. Though the low level Socket APIs provide this functionality (Socket.isConnected() ), but same functionality is not available through any higher level APIs. Not sure if you any compulsions of using Servlet APIs or you can use low level socket APIs.

    0 讨论(0)
提交回复
热议问题