简体   繁体   中英

WebSocket without SSL doesn't work in Chrome

In 2013 I tried Websockets out with Alchemy ( http://alchemywebsockets.net/ ). Now I'm trying to make a new project, but the WebSocket doesn't receive or send nothing.

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.

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.

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. In the last version of Google Chrome websockets without SSL works fine now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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