Im writing custom Websocket server using c#. I wrote some code, according to this mozilla guide. Now I'm succesfully handshaking and receiving messages from my client, and all it working on Chrome, but when I'm trying to send message from server on FireFox, im getting console error "The connection to ws://localhost:80 was interrupted while the page was loading". I'm sending Encoded message, using alghorithm from this page and client side exactly the same from websocket echo test. You can find whole project on GitHub
I've tried sending not encoding bytes and reopen websoket connection each time i send a message).
As you see, server automatically sends message "Hello" to the client. Process Function(new thread for each client):
public void Process()
{
try
{
Stream = _client.GetStream();
HandShake();
while (true)
{
while (_client.Available < 3)
{
}
Byte[] bytes = new Byte[_client.Available];
Stream.Read(bytes, 0, bytes.Length);
var message = GetMessage(bytes);
if (_webSocketConverter.IsClosing(bytes[0]))
{
break;
}
message = GetMessage(bytes);
SendMessageFromServer("Hello");
}
}
catch (Exception ex)
{
throw ex;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
Console.ResetColor();
}
finally
{
_server.RemoveConnection(this._userInfo.Id);
Console.WriteLine("Client {0} disconnected from the server", this._userInfo.Id);
Close();
}
}
SendMessage Function(EncodeMessage - algorithm from link above, nicely working with chrome)
private void SendMessageFromServer(string message)
{
Byte[] messageByte = _webSocketConverter.EncodeMessage(message);
Stream.Write(messageByte);
}
Seems like problem with server, because websocket.org/echo working with firefox.