Jump to content
Larry Ullman's Book Forums

Websockets Question


Recommended Posts

I was looking at the following page today about the new WebSockets API:

http://code.google.com/p/phpwebsocket/

 

I understand all the client and server code, but I couldn't understand the following step in the procedure below the code:

2. From the command line, run the server.php program to listen for socket connections.

 

How do I do this? Where's the command line for an Apache server? How do you run a PHP script from the command line? After performing this step, will the PHP script run forever on the server, making it always available when a WebSocket is needed, or is this a step that must be executed every time I want to open a socket for bi-directional communication?

 

Thank you all in advance.

Link to comment
Share on other sites

How you run PHP from the command line really depends upon what OS you're running and how you installed PHP.

 

Yes, if I read that code correctly, the server.php script will continue to run to listen for incoming connections.

Link to comment
Share on other sites

It's a new API to the HTML5 draft, but basically, it allows for bi-directional communication and asynchronous messaging. In essense, it allows for more dynamically responsive applications like chat services, video conversations, chess games that respond instantly to an opponent's move, etc., etc.

 

It really is a great thing, actually, as Java has had asynchronous messaging forever, but it has always been missing from HTML. I imagine that in time it will have as big an effect on the Web as Ajax has up till now.

 

I built a rudimentary chat application the other day using the WebSocket API and Ajax long polling for non-HTML5 browsers. It wasn't as hard as I thought.

Link to comment
Share on other sites

Looks like the best of both worlds. A full-duplex, handshaken, non-reliable way of sending messages. Sounds like a combination of TCP and UDP without the shortcomings.

 

Maybe I'll start creating a live football match part of my website or something? Would be a great way of keeping my fans updated under a match. :)

Link to comment
Share on other sites

Yes, exactly. "The best of both worlds." I like that.

 

In a couple years, as this API gets wider browser support and recognition, I have no doubt that it'll become the new standard for websites/Web apps, similar to what Ajax sites are now compared to older-style sites.

 

I can already thing of a million applications for this thing. Basically, this is a big part of the puzzle in trying to make the move to Desktop-like apps, games, etc.

Link to comment
Share on other sites

 Share

×
×
  • Create New...