带有PHP的HTML5 WebSockets(WAMP)



这是一个用PHP实现的简单HTML5 WebSockets服务器的演示。现在,服务器仅连接一堆用户,从每个用户接收消息,然后向所有其他客户端广播相同的文本。

服务器遵循草案76。我已经尝试了几篇有关设置自定义PHP服务器的文章和教程,但是没有什么帮助。最有用的一个是在NetTuts上发布的一个,但即使这样也只能将我带到目前为止。

我目前的目标(因为这是我正在为网络课程进行的最终项目的一部分)是使用套接字编写一个模拟股票交易的应用程序。几个用户将登录并看到他们可以购买其股票的一些公司,然后所有信息都会实时更新。

我喜欢HTML5 WebSockets的地方是,绝对不需要AJAX。使用AJAX,为了使每个人都能立即保持同步,您必须多次调用服务器。使用WebSocket,您在前端(客户端)唯一要做的事情就是设置一个回调函数来处理来自服务器的消息。而已!

一旦完成,我将在此以及最终项目中获得详细的教程。

有关此项目以及我正在进行或正在进行的其他项目的更多信息,请访问我的产品组合,网址为http://www.rodrigo-silveira.com

9 comments
  1. how about some tutorials, examples, and step by step setups with more practical applications?  chat apps is always the first thing mentioned when talking about websockets.  not everyone wants chat apps.  how about an app where it's not just new info being inputted that displays right away on multiple clients… how about an app where data that is already saved on a database is displayed and that data can edited and re-edited by multiple people on multiple computers and the new data is shown to all clients in real-time.  sort of like the dead project called Google Wave, and their current application called Google Docs where there is multi-person collaboration on the documents and everyone sees the changes made by everyone else as soon as they happen.  how about some easy to follow video lessons on that?  reading manuals and documentation to learn things is not fun or quick.  it's faster when someone explains it and shows examples and maybe even provides downloads to quickly setup a working example on your own server.

  2. I have same problem it did not connect on localhost (WAMP) i also given server.php file path : localhost:8005/chat-app/server.php & i changed in php.ini enable sockets_dll then socket_bind is not defined error showing , please anybody help to resolve.

  3. how can I use the socket?

    I use wamp on windows, I was in command of the windows and typed:

    c: wamp bin php php5.3.5 php-q server.php

    and shows the error:

    Fatal error: Call to undefined function socket_create ()

  4. @casperbyc I've posted a more elaborate video of the WebSocket server in PHP titled 'HTML5 Websockets Tutorial & Demo'
    I'm working on a written tutorial right now, which I'm planning to follow up with a video tutorial. Stay tuned…

  5. can you explain how you set the server up or provide php server script? I tried many time but seems like all failed under php…. ><''

Comments are closed.