Mobile app version of vmapp.org
Login or Join
Lengel546

: Is there a way to return a response every x seconds or so to a single http request? I'm wondering if it's possible to send a response every second or so to a single http request. Like for

@Lengel546

Posted in: #Http

I'm wondering if it's possible to send a response every second or so to a single http request. Like for example the client makes an http request, then the server sends a space character every second. This could be never ending or with a limit, for example a minute.

I think the word 'response' is misleading in this context, since I don't necessarily mean an http response. The whole http response could be composed of the space characters, which would mean a single http response to a single http request, except that it is a minute long.

I tried chunked encoding but I don't think it works, or at least my implementation's wrong.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Lengel546

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jessie594

You can use WebSockets to accomplish server-side pushing to the client. They allow you to open a connection to a server and receive responses from the server without issuing further requests from the client.

The websocketstest page shows a WebSocket connection working in your browser (if it supports WebSockets), with an update of the server time pushed to the client every second.

The socket.io JavaScript library is a popular way to implement a WebSocket on the client side, with fallbacks for older browsers and support for multiple sockets.

You'll also need to create a websocket server to listen for connections and serve responses. There are libraries for PHP, Java, Ruby, node.js, Python, and others. There's a tutorial here that talks you through the client and server -side setup.

Note that not all browsers support WebSockets by default, although the socket.io library attempts to workaround this [details].

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme