Linux - WebSocket测试错误 [英] Linux - WebSocket test error

查看:101
本文介绍了Linux - WebSocket测试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试打开websocket和echo。
我试图在基于Linux的PC上运行,并在官方websocket网站使用示例代码进行测试http://www.websocket.org/echo.html '
我只是将代码复制并保存为HTML文件。但是,当我访问
'127.0.0.1/websocket.html'时,只有HTML代码出现在屏幕上,无法使用JavaScript文件。我用我的笔记本电脑完全相同的代码,它是基于窗口的,它工作正常。我使用网络浏览器作为Chromium 10.0.648.133 Ubuntu 10.04
您能否帮我解决问题?代码如下。

I am testing on opening websocket and echo. I am trying to run on Linux-based PC and testing with example code in the official websocket website 'http://www.websocket.org/echo.html' I just copied the code there and saved as HTML file. But, when I access '127.0.0.1/websocket.html' , only HTML code is appeared on the screen, no working with JavaScript file. I tried exact same code with my laptop which is window-based, it works correctly. I am using a web browser as "Chromium 10.0.648.133 Ubuntu 10.04" Can you please help me out? The code is here below..

    <!DOCTYPE html>
    <meta charset="utf-8" />
    <title>WebSocket Test</title>
    <script language="javascript" type="text/javascript">
    var wsUri = "ws://echo.websocket.org/";
    var output;

    function init() {
    output = document.getElementById("output");
testWebSocket();


}

function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}

function onOpen(evt) {
writeToScreen("CONNECTED");
doSend("WebSocket rocks");
}

function onClose(evt) {
writeToScreen("DISCONNECTED");
}

function onMessage(evt) {
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
websocket.close();
}

function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}

function doSend(message) {
writeToScreen("SENT: " + message);
websocket.send(message);
}

function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}

window.addEventListener("load", init, false);

</script>
<h2>WebSocket Test</h2>
<div id="output"></div>
</html>


推荐答案

操作系统完全与WebSocket无关或不。这是一个浏览器问题。 Firefox,Chromium或任何其他支持每个平台上的Web开发人员都可以使用的功能。

The operating system has absolutely nothing to do with WebSocket working or not. This is a browser issue. Firefox, Chromium or whatever provide the same features to web developers on every platform they support.

Chromium 10只有部分支持 WebSocket,这意味着它支持旧版本的标准/协议,或者您必须手动启用它们。只需更新您的浏览器。 Chromium 10于2011年3月发布,因此在当前几乎每个浏览器版本都添加了新的HTML5功能的情况下都很旧。

Chromium 10 has only partial support for WebSocket, which means it supports an old version of the standard/protocol or you must enable them manually. Just update your browser. Chromium 10 was released in March 2011 and thus is quite old in this current situation where new HTML5 features are added to almost every browser release.

这篇关于Linux - WebSocket测试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆