One of the cool new features in HTML5 is WebSockets , which allow us to talk to the server without AJAX requests. Today Bin Go will let you run WebSocket through the server side of the Php environment, create a client and send and receive server-side information through the WebSockets protocol.
You can also refer to the following HTML5 related articles:
" Basic Tutorial on HTML 5 Canvas "
" Solution to make all IE support HTML5 "
" Feel the power of HTML5 and CSS3 together "
What are WebSockets?
WebSockets is a technology for two-way communication on a (TCP) interface, PUSH technology type. At the same time, WebSockets will still be based on the W3C standard. So far, the latest versions of Chrome and Safari browsers already support WebSockets.
What will WebSockets replace? WebSockets can replace Long Polling (PHP server push technology), which is an interesting concept. The client sends a request to the server. Now, the server will not respond to data that is not ready. It will keep the connection open until the latest data is ready to be sent. After that, the client receives the data and sends another request. . This has its benefits: it reduces latency on either connection and eliminates the need to create a new connection when one is already open. But Long-Polling is not a fancy technology. It is still possible that request suspension will occur, so a new connection will need to be established.
Some AJAX applications use the above techniques - this is often attributed to low resource utilization.
Just imagine, what a great thing it would be if the server would start itself up in the morning and send data to clients that want to receive it without having to set up some connection ports in advance! Welcome to the world of PUSH technology!
Step 1: Get the WebSocket server
This tutorial will focus more on client creation rather than server-side execution and other operations.
I'm using XAMPP on Windows 7 to run PHP locally. phpwebsockets is a PHP WebSocket server. (In my experience, this version has some minor problems. I have made some modifications to it and uploaded the source files to share with everyone) The following different versions can also implement WebSocket. If one does not work, you can try other versions. Or continue with the tutorial below.
jWebSocket (Java)
web-socket-ruby (ruby)
Socket IO-node (node.js)
Start the Apache server