0
2013年,我用鍊金術(http://alchemywebsockets.net/)試過了Websocket。現在我正在嘗試創建一個新項目,但WebSocket沒有收到或不發送任何內容。沒有SSL的WebSocket在Chrome中不起作用
我做了一些研究,發現一個網站,您可以測試WebSockets(http://www.websocket.org/echo.html),奇怪的是沒有SSL/TLS的WebSocket甚至沒有工作。
現在,我發現了一個名爲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);
}