1

In the traditional way for every client request I get servlet response.
something like this:

HttpResponse response = client.execute(request)

Now I want to get updates from my servlet every time interval.
How can i catch the server's response?

For comparison when I worked with sockets the code looked something like this:

public void run()
{
    while(true)
    {            
        Object serverMessage = inStream.readObject();               
        // Do somthing with serverMessage
    }
}
M A
  • 71,713
  • 13
  • 134
  • 174
Rami
  • 2,098
  • 5
  • 25
  • 37

2 Answers2

1

No. The client will have to make more requests to which the server -> servlet then responds.

You can however (by e.g. Javascript) try to make the client send a request at a regular interval.

ChristopheD
  • 112,638
  • 29
  • 165
  • 179
1

You can simulate a server to client push with an approach called long polling, addressed here: Long Polling example
HTTP is a request driven protocol. You could explore other messaging protocols depending on what you're doing. Anything from Web Sockets to basic TCP, to a variety of frameworks that build ostensibly richer apis on top of tcp. What are you trying to accomplish?

Community
  • 1
  • 1
verrdon
  • 71
  • 2