【问题标题】:WebSocket without SSL doesn't work in Chrome没有 SSL 的 WebSocket 在 Chrome 中不起作用
【发布时间】:2014-02-26 15:33:09
【问题描述】:

2013 年,我使用 Alchemy (http://alchemywebsockets.net/) 尝试了 Websockets。现在我正在尝试创建一个新项目,但 WebSocket 没有接收或发送任何内容。

我做了一些研究,发现了一个可以测试 WebSockets 的网站 (http://www.websocket.org/echo.html),奇怪的是没有 SSL/TLS WebSockets 甚至都无法工作。

现在,我发现了一个名为 web-socket-js 的项目,它使用 Flash 作为 WebSocket,它在 FireFox 上运行良好,但在 Chrome 中仍然失败。

希望有人能帮帮我,

我正在使用以下代码:

服务器端:

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);
}

客户端:

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);
}

【问题讨论】:

标签: c# javascript google-chrome websocket


【解决方案1】:

Google Chrome 似乎存在错误。在最新版本的 Google Chrome 中,没有 SSL 的 websockets 现在可以正常工作了。

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 2017-08-20
    • 2013-04-17
    • 2018-11-15
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    相关资源
    最近更新 更多