jchristn / WatsonWebsocket

A simple C# async websocket server and client for reliable transmission and receipt of data
MIT License
277 stars 53 forks source link

It only supports Sec-WebSocket-Version: 13. #118

Closed hasancaktar closed 10 months ago

hasancaktar commented 1 year ago

First of all, thank you very much for developing such a great project. It only supports version 13. I would love to have it set for all websocket versions. I want it to connect to all websokcet versions without version checking. Tools I use: Postman, Hercules. I used the XiaoFeng Library. this library supports them all. You can try

OS Win10 .net 7.0 runtime

11 connecting with protocol version 13

22 Not connection

s XiaoFeng package

jchristn commented 1 year ago

This library relies on the underlying http.sys implementation. Meaning we simply abstract the Websocket capabilities of the framework and OS.

hasancaktar commented 1 year ago

then should I change the websocket versions supported by the operating system? If this is the solution, how should I make this change?

jchristn commented 1 year ago

Which framework/runtime and operating system are you using?

hasancaktar commented 1 year ago

I am using Windows 11 operating system and I am using .net core runtime. I used android device, postman programs as client. I can send you more detailed information if you want. photo video etc.

jchristn commented 1 year ago

Hi @hasancaktar I wasn't able to find anything about what versions are supported on Windows. Honestly I'm not sure how to even approach this problem! Marking as 'help wanted'.

hasancaktar commented 1 year ago

I shared the server codes I tested. maybe i am doing something wrong. Can you review please. I updated the issue. I detailed the error.

` using System.Net.WebSockets; using System.Text; using WatsonWebsocket;

namespace AppServer_Watson { internal class Program {

    static string hostName = "127.0.0.1";
    static int port = 8080;
    static bool ssl = false;
    private static WatsonWsServer server = new WatsonWsServer(hostName, port, ssl);

    static List<Guid> clients = new List<Guid>();

    static void Main(string[] args)
    {

        server.ClientConnected += ClientConnected;
        server.ClientDisconnected += ClientDisconnected;
        server.MessageReceived += MessageReceived;
        server.Start();

        Console.WriteLine($"Server Started...   Hostname: {hostName}:{port} | SSL: {ssl}\n");
        Console.ReadLine();

    }

    static void ClientConnected(object sender, ConnectionEventArgs args)
    {
        clients.Add(args.Client.Guid);
        Console.WriteLine("\nClient connected: " + args.Client.ToString());

        var client = clients.Last();
        server.SendAsync(client, "Welcome", WebSocketMessageType.Text);

        Console.WriteLine("All clients: "+clients.Count +"\n");
    }

    static void ClientDisconnected(object sender, DisconnectionEventArgs args)
    {
        Console.WriteLine("\nClientdisconnected: " + args.Client.ToString());
        clients.Remove(args.Client.Guid);

        Console.WriteLine("All clients: " + clients.Count + "\n");

    }

    static void MessageReceived(object sender, MessageReceivedEventArgs args)
    {
        Console.WriteLine("Received message: "+ Encoding.UTF8.GetString(args.Data)+"  |  "+"Client: "+ args.Client.ToString());

        foreach (var client in clients)
        {
            server.SendAsync(client, Encoding.UTF8.GetString(args.Data), WebSocketMessageType.Text);
        }
    }
}

}`

MacKey-255 commented 1 year ago

@hasancaktar This line is the problem: Captura de pantalla_2023-02-03_21-01-20 The HttpWebSocket provide by Microsoft .NET library only allow WebSocket 13 version. RFC 6455: The WebSocket Protocol. @jchristn try to handle WebSocketException in WatsonWebsocket.cs line 425 for show error message and close connection. Take a look at this question. SAlu2s

hasancaktar commented 1 year ago

@hasancaktar This line is the problem: Captura de pantalla_2023-02-03_21-01-20 The HttpWebSocket provide by Microsoft .NET library only allow WebSocket 13 version. RFC 6455: The WebSocket Protocol. @jchristn try to handle WebSocketException in WatsonWebsocket.cs line 425 for show error message and close connection. Take a look at this question. SAlu2s

Yes, this is the source of my problem. Thank you my friend for finding the problem. I don't have my computer with me right now so I can't control it. I wonder if we can adjust for all versions here. Or can we remove version control completely?

jchristn commented 1 year ago

Hi @hasancaktar just to be clear, that line of code is in the underlying platform (which WatsonWebsocket sits on top of) so I don't have the ability to modify it.

Hi @MacKey-255 I love the suggestion and will implement the appropriate exception handler for this. Thank you!

jchristn commented 10 months ago

Moving this to discussion as there is unfortunately nothing that we can do about it.