[英]WebSocket without SSL doesn't work in Chrome
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);
}
似乎Google Chrome浏览器存在错误。 在没有SSL的最新版本的Google Chrome浏览器中,现在可以正常使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.