Rami
Rami

Reputation: 2148

Can a client get servlet's responses without a request?

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
    }
}

Upvotes: 1

Views: 1144

Answers (2)

verrdon
verrdon

Reputation: 71

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?

Upvotes: 1

ChristopheD
ChristopheD

Reputation: 116287

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.

Upvotes: 1

Related Questions