PDA

View Full Version : Socket Functionality with Ajax?



???
06-17-2007, 04:39 PM
I was wondering if you could send a request on page load, and the server could wait until it wanted to send you something (like a new thread in a forum) and then you would start another request to give your answer and the server would wait on that. And it would continue. Would that work? My friend said no, but the reason he gave was absurd.

mwinter
06-17-2007, 04:49 PM
I was wondering if you could send a request on page load, and the server could wait until it wanted to send you something (like a new thread in a forum) and then you would start another request to give your answer and the server would wait on that. And it would continue. Would that work?

Depends how long the wait is: the connection would time-out if it were much longer than say, thirty seconds. Keep in mind that HTTP is a stateless request-response protocol. The only reason to maintain a connection is to reduce traffic: to share the connection for a number of requests. Even so, the connection is still transient.

???
06-17-2007, 04:53 PM
Thanks for the help, but there's some way to change the timeout time, isn't there?

mwinter
06-17-2007, 05:16 PM
Thanks for the help, but there's some way to change the timeout time, isn't there?

No. The client will have it's own time-out threshold, and so will the server. You might be able to affect how long the server is willing to wait, but you cannot control when the client will decide to close the connection.