views:

139

answers:

3

Today I thought about why the Web traditionally is stateless - opening a connection, then close it as fast as possible.

I realized that this was the HTTP.

And soon we will have fully implemented web-sockets to use for live things.

So I thought, could websockets replace http in the future so that every connection made will be opened til the client disconnects? Why would we want to open -> close, open -> close and so on like we do today?

A: 

Simply put, this won't happen, because leaving the connection up takes more resources.

On a "typical" website, much more time is spent reading content vs. requesting content. So why bother keeping a connection around, wasting server resources, when there's no need for further data until the end user performs some sort of user interaction?

jvenema
But that is just how it looks like today. Server-push requires opened connections. Now we will have two protocols, HTTP and Websockets. And I guess the future will be using websockets over http for greater user-experience. That is why my question is focused on "the future".
never_had_a_name
The future might also hold something beyond web sockets. In the future the "web" might be: That's soo 2010.
Ryan Ternier
Seriously, what's up with the downvotes? My answer is essentially the same as @Ryan...
jvenema
@jvenema +1 for mentioning my name. now do it again. do it... do it...
Ryan Ternier
LOL, +1 on the comment from...wait for it...@Ryan
jvenema
+4  A: 

Originally HTTP was for simply transferring a single document. The connection was closed, because the request was complete. There was no need for the connection to remain open. These days we have a whole mess of web applications, and we have entire layers of complexity built up to keep a persistent state despite closing and reopening connections. It really is ridiculous. We have entire applications built around a protocol that was designed for something quite different, all because of issues with the end user. (We didn't want to make them download anything, make them click more than they had to, confuse them, etc.)

I don't think it will be too much longer before we clean house a bit and remove all of these layers and get down to business with what our applications are trying to accomplish. I am speaking of not just the protocol used, but the layers of abstraction for execution as well.

At the very least, most HTTP connections are persistent to an extent. There is a keep-alive parameter so that many requests from the same server can be processed all in one TCP connection. Not all servers have it enabled, but many do, and it does keep things moving better than without it.

Brad
One reason Flash/Silverlight will continue to exist on websites (HTTP layer). It does many things that can't be done over HTTP using HTML. HTML 5 is great, amazing, and down right sexy, however for us that develop in the "real world" where users still run windows 98 and ME (ugh), it won't catch on as fast as it should. I look forward to the day when this happens, but I'm not holding my breath.
Ryan Ternier
I certainly don't believe HTML 5 is the answer. I hold the theory that the only reason applications started being built with Flash was because the Java runtime got bloated to 100MB+ and took forever to load. Including Flash with Windows 98 and later definitely helped penetration. Why build a Java applet when an 8k SWF loads nearly instantly for 98% of your users? Plus, you definitely have the built-in animation and vector graphics, but I don't believe that was the selling point.
Brad
+3  A: 

HTTP was build upon TCP/IP. Though TCP/IP is stateful, HTTP is stateless. The packets sent between the client and the server don't know about each other.

Though you can Mimic stateful by using cookies, sessions etc.

Implementing a StateFul world would mean increases server load, more connections, more hits.

All those connections ON all the time? I don't know if they could build servers fast enough. Google would implode, and even Chuck Norris wouldn't be able to hold FaceBook together if that happened.

Ryan Ternier
+1 for Chuck Norris :)
never_had_a_name
But, with the current stateless requests, isn't there a lot of unnecessary overhead for many web applications. It seems like a connection ON all the time would help in this regard. Google Docs hasn't imploded yet.
stjowa
@Ryan Dude, better hope Chuck doesn't see what you wrote there.
bzlm
@stjowa there is a lot of unnesseary data that is transfered back and forth. Thankfully JSON, XML, web services, AJAX has come to the rescue, but it's still stateless. The client knows there "is" a server, the server knows there "is" a client, but the 2 will only meet each other when a transaction takes place.
Ryan Ternier