Reputation: 184
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);
}
Upvotes: 1
Views: 4972
Reputation: 184
Seems like there was a bug with Google Chrome. In the last version of Google Chrome websockets without SSL works fine now.
Upvotes: 1