简体   繁体   English

没有SSL的WebSocket在Chrome中不起作用

[英]WebSocket without SSL doesn't work in Chrome

In 2013 I tried Websockets out with Alchemy ( http://alchemywebsockets.net/ ). 2013年,我在Alchemy( http://alchemywebsockets.net/ )上试用了Websockets。 Now I'm trying to make a new project, but the WebSocket doesn't receive or send nothing. 现在,我正在尝试创建一个新项目,但是WebSocket不会接收任何内容。

I did do some research and found a website where you can test WebSockets ( http://www.websocket.org/echo.html ), the weird part is that without SSL/TLS WebSockets doesn't even work. 我做了一些研究,发现了一个可以测试WebSockets的网站( http://www.websocket.org/echo.html ),奇怪的是没有SSL / TLS的WebSockets甚至无法工作。

Now, I found a project called web-socket-js which uses Flash as WebSocket, it works great on FireFox, but it still fails in Chrome. 现在,我找到了一个名为web-socket-js的项目,该项目使用Flash作为WebSocket,在FireFox上运行良好,但在Chrome中仍然失败。

I hope someone can help me out, 我希望有人能帮助我,

I'm using the following codes: 我正在使用以下代码:

Server Side: 服务器端:

public WSServer()
{
    WSServer.Instance = this;

    this.webSocketServer = new WebSocketServer(81, IPAddress.Any)
    {
        OnConnected = OnConnected,
        OnReceive = OnReceive,
        OnDisconnect = OnDisconnect,
        TimeOut = new TimeSpan(24, 0, 0)
    };
    this.webSocketServer.Start();

    Console.WriteLine("Started Server");
}

private void OnConnected(UserContext context)
{
    Console.WriteLine("Connected!");
}

private void OnDisconnect(UserContext context)
{
    Console.WriteLine("Disconnected");
}

private void OnReceive(UserContext context)
{
    string dataString = context.DataFrame.ToString();
    Console.WriteLine("Got message " + dataString);
}

Client Side: 客户端:

try{
    socket = new WebSocket("ws://127.0.0.1:81/");

    socket.onopen = function(){
        console.log("Connection open!");
    };

    socket.onmessage = function(msg){
        console.log("Message: " + msg);
    };

    socket.onclose = function(){
        console.log("Connection closed.");
    };      
} catch(exception){
     console.log('Error: ' + exception);
}

Seems like there was a bug with Google Chrome. 似乎Google Chrome浏览器存在错误。 In the last version of Google Chrome websockets without SSL works fine now. 在没有SSL的最新版本的Google Chrome浏览器中,现在可以正常使用。

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

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