简体   繁体   English

Websocket能够从ajax接收数据吗?

[英]Can Websocket able to receive data from ajax?

I am trying to building a php and html5 websocket chat system where one end will be socket and other end will be ajax. 我正在尝试构建一个php和html5 websocket聊天系统,其中一端是套接字,另一端是ajax。 Is it possible PHP's socket_recv() function receive data from ajax/mysql or from any other source(which is not send by "send" method or socket)? PHP的socket_recv()函数是否有可能从ajax / mysql或任何其他源(不是通过“发送”方法或套接字发送的)接收数据?

** We want one end in ajax because still websocket is not supported by all browser specially IE. **我们希望以ajax结尾,因为所有浏览器(特别是IE)仍不支持websocket。

Please help. 请帮忙。

If you're not going to use WebSockets on the client end, you don't need them on the server side either. 如果您不打算在客户端使用WebSockets,则在服务器端也不需要它们。 (Indeed, you can't use them unless both parties support them.) AJAX creates normal HTTP requests; (实际上,除非双方都支持,否则您将无法使用它们。)AJAX创建普通的HTTP请求。 you can handle them just like any other request in PHP. 您可以像处理PHP中的其他任何请求一样处理它们。

Also, critically: the PHP socket_ functions are raw TCP/UDP sockets, not WebSockets. 另外,至关重要的是:PHP socket_函数是原始TCP / UDP套接字, 而不是 WebSocket。 The WebSocket protocol is considerably more complicated than they support directly. WebSocket协议比直接支持的协议复杂得多。 PHP sockets can be used in the process of implementing WebSockets, but it's much better to use a library like Ratchet which has already done the heavy lifting for you. PHP套接字可以在实现 WebSocket的过程中使用,但是最好使用Ratchet之类的库,该库已经为您完成了繁重的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM