[英]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.