Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7165783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:18:27+00:00 2026-05-28T14:18:27+00:00

I have the same question that was asked in another post except I’m having

  • 0

I have the same question that was asked in another post except I’m having the issue in version 13 (RFS 6455). Has anyone succeeded in implementing a web socket server using this version? I’ve tried all the other suggestions I could find, but none of them worked.

Related Post:
Websocket server: onopen function on the web socket is never called.

Client is javascript on Chrome 16.
Server is a C# console application.

My server is able to receive the client handshake and successfully send a response, but the onopen/onmessage event is not being triggered on the client.

It seems the issue for most people online is with the handshake message itself, but all the examples I can find are for -75 or -76 version.

I am following the instructions here:
https://www.rfc-editor.org/rfc/rfc6455#page-39

Here I initialize my server handshake response.

handshake = "HTTP/1.1 101 Switching Protocols" + Environment.NewLine;
handshake += "Upgrade: websocket" + Environment.NewLine;
handshake += "Connection: Upgrade" + Environment.NewLine;
handshake += "Sec-WebSocket-Accept: ";

This is where I receive the client handshake message, generate my response key and send it back.

System.Text.ASCIIEncoding decoder = new System.Text.ASCIIEncoding();
string clientHandshake = decoder.GetString(receivedDataBuffer, 0, receivedDataBuffer.Length);
string[] clientHandshakeLines = clientHandshake.Split(new string[] { Environment.NewLine }, System.StringSplitOptions.RemoveEmptyEntries);

foreach (string line in clientHandshakeLines)
{
    if (line.Contains("Sec-WebSocket-Key:"))
    {
        handshake += ComputeWebSocketHandshakeSecurityHash09(line.Substring(line.IndexOf(":") + 2));
        handshake += Environment.NewLine;     
    }
}

byte[] handshakeText = Encoding.ASCII.GetBytes(handshake);
byte[] serverHandshakeResponse = new byte[handshakeText.Length];
Array.Copy(handshakeText, serverHandshakeResponse, handshakeText.Length);

ConnectionSocket.BeginSend(serverHandshakeResponse, 0, serverHandshakeResponse.Length, 0, HandshakeFinished, null);

The client side code looks like this.

ws = new WebSocket("ws://localhost:8181/test")
ws.onopen = WSonOpen;
ws.onmessage = WSonMessage;
ws.onclose = WSonClose;
ws.onerror = WSonError;

Sample Client Handshake

[0]: "GET /test HTTP/1.1"
[1]: "Upgrade: websocket"
[2]: "Connection: Upgrade"
[3]: "Host: localhost:8181"
[4]: "Origin: http://localhost:8080"
[5]: "Sec-WebSocket-Key: jKZrBlUEqqqstB+7wPES4A=="
[6]: "Sec-WebSocket-Version: 13"

Sample Server Response

[0]: "HTTP/1.1 101 Switching Protocols"
[1]: "Upgrade: websocket"
[2]: "Connection: Upgrade"
[3]: "Sec-WebSocket-Accept: mL2V6Yd+HNUHEKfUN6tf9s8EXjU="

Any help would be great. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:18:28+00:00Added an answer on May 28, 2026 at 2:18 pm

    One thing you did not post is what Environment.NewLine and HandshakeFinished are equal to.

    The headers must comply with RFC 2616. In other words, each header line must end with CR+LF (carriage return + line feed or ASCII character 13 followed by ASCII character 10). The last header must be followed by an additional CR+LF in addition to the one indicating the end of the header line.

    Also, although it’s not causing you issues yet because your client code isn’t setting it, you are also missing logic to handle sub-protocol selection. If the client sends a Sec-WebSocket-Protocol header, you must choose from one of the sub-protocols and return it in a Sec-WebSocket-Protocol response header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have another question. Quite similar to the other that i already asked (and
I hope that this question has not been asked elsewhere, but I'm having difficulty
vb.net windows forms question. I've got 3 forms that have exactly the same functions,
Along the same vein as the questions asked yesterday, I have another count if
I'm sure this question has already been asked in one form or another, but
As per another question I had asked earlier I think I may have found
I know that maybe this question has been asked before, but I can't seem
I know this question has been asked multiple number of times and i have
My apologies if this is just another question that gets asked over and over.
I have the same question problem as described here How to purge a cached

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.