Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么websocket只能与websocket.org一起使用_Javascript_Php_Html_Websocket - Fatal编程技术网

Javascript 为什么websocket只能与websocket.org一起使用

Javascript 为什么websocket只能与websocket.org一起使用,javascript,php,html,websocket,Javascript,Php,Html,Websocket,为什么websocket只能与websocket.org一起使用,而不能通过localhost使用?我得到的只是javascript中未定义的内容。ws://websocket.org有什么特别之处 到“ws://localhost/includes/php/UnitTest/WebSocketTest.php”的WebSocket连接失败:WebSocket握手期间出错:意外响应代码:200 我已经尝试了所有端口号ws://localhost:80/相同的问题 <script langu

为什么websocket只能与websocket.org一起使用,而不能通过localhost使用?我得到的只是javascript中未定义的内容。
ws://websocket.org
有什么特别之处

到“ws://localhost/includes/php/UnitTest/WebSocketTest.php”的WebSocket连接失败:WebSocket握手期间出错:意外响应代码:200

我已经尝试了所有端口号
ws://localhost:80/
相同的问题

<script language="javascript" type="text/javascript">
    var ws = new WebSocket("ws://127.0.0.1:80/includes/php/UnitTest/WebSocketTest.php");
    ws.onopen = function() { alert("open");}
    ws.onerror = function(e){alert(e.reason+ " " + e.code);}

</script>

var ws=newwebsocket(“ws://127.0.0.1:80/includes/php/UnitTest/WebSocketTest.php”);
ws.onopen=function(){alert(“open”);}
ws.onerror=函数(e){alert(e.reason+“”+e.code);}
我正在读两本书《HTML5 WebSocket的权威指南》和《O'Reilly WebSocket的权威指南》,他们都没有谈论或指出这个问题,我还以为这都是标准的东西呢


您能帮忙吗?

您的服务器端必须准备好接受WebSocket连接


在PHP中,您可以使用它。您可以在这里找到一个基本教程:

这可能是因为您在PHP代码中没有正确处理WebSocket。HTTP 200意味着页面将像普通网页一样返回,而不是返回HTTP 101以切换到websocket。显示您用于处理连接的代码。感谢您的响应。我只是觉得它就像XHR一样,您可以从javascript omg将内容发布到php$\u post['stuff'],我现在得到了“到'ws://localhost:8181/includes/php/UnitTest/WebSocketTest.php'的WebSocket连接失败:连接建立错误:net::ERR_connection_拒绝我缺少什么?你缺少了整个WebSocket:D。XHR只是JS发出HTTP请求的能力。WebSockets是一种不同的通信机制,尽管它从HTTP连接开始。