Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wss issue "The client and server cannot communicate, because they do not possess a common algorithm" #177

Closed
Sergio1C opened this issue Sep 19, 2020 · 2 comments

Comments

@Sergio1C
Copy link

Sergio1C commented Sep 19, 2020

Hi.
I trying to use this package but getting output message as shown on titile

`
/// Using a test's web socket echo server at: https://www.websocket.org/echo.html
[TestClass]
public class WebSocket4Net_UnitTest
{
private readonly string webSocketHost = "wss://echo.websocket.org/";
private readonly string echoCommand = "Hi, Kaazing! How are you?";

    private WebSocket websocket;

    [TestMethod]
    public void TestConnection_WhenPutCommandFirst_ExpectedCorrectResult()
    {
        //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        websocket = new WebSocket(uri: webSocketHost);
        websocket.Opened += new EventHandler(websocket_Opened);
        websocket.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>(websocket_Error);
        websocket.Closed += new EventHandler(websocket_Closed);
        websocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(websocket_MessageReceived);
        websocket.Open();

        while (websocket.State == WebSocketState.Connecting)
        {
            Thread.Sleep(500);
        }
    }

    void websocket_Opened(object sender, EventArgs e)
    {
        Debug.WriteLine($"Websocket opened");
        this.websocket.Send($"{echoCommand}");

    }

    void websocket_MessageReceived(object sender, MessageReceivedEventArgs e)
    {
        Debug.WriteLine($"Message received: {e.Message}");
    }

    void websocket_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
    {
        Debug.WriteLine($"Error: {e.Exception.Message}");
    }

    private void websocket_Closed(object sender, EventArgs e)
    {
        Debug.WriteLine($"Websocket closed: {e}");
    }
}`

After some googling i found a possible solution but it isn't helped me.
I have tried to change target .Net framework for 4.6.2 also but got the same.

If to try with ws uri (webSocketHost = "ws://echo.websocket.org/") it will work. . I'm assumpting it may be related with some of TLS issue? Can you help.

image

@coxantohi
Copy link

I think that the problem is related to the code found in the PR #123.
In the WebSocket4Net/WebSocket.NoSilverlight.cs file there is the following line:
private SslProtocols m_SecureProtocols = SslProtocols.Default;
I think it should be
private SslProtocols m_SecureProtocols = SslProtocols.None;

If we look at SslProtocols Enum we see

for Default:

Use None instead of Default. Default permits only the Secure Sockets Layer (SSL) 3.0 or Transport Layer Security (TLS) 1.0 protocols to be negotiated, and those options are now considered obsolete. Consequently, Default is not allowed in many organizations. Despite the name of this field, SslStream does not use it as a default except under special circumstances.

for None:

Allows the operating system to choose the best protocol to use, and to block protocols that are not secure. Unless your app has a specific reason not to, you should use this field.

@kerryjiang
Copy link
Owner

Please try WebSocket4Net 1.0.0-beta.2.
https://www.nuget.org/packages/WebSocket4Net/1.0.0-beta.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants