Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
HartleySan

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

You might have to ask your hosting service to execute that script for you. You could ask for telnet access, but I wouldn't expect them to allow it since it would make it easier for you to access other customer's folders on the same server.

  • Upvote 1

Share this post


Link to post
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.

Share this post


Link to post
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. :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...