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 6923813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:35:02+00:00 2026-05-27T10:35:02+00:00

I try to create my own websocket server. It works good with Safari and

  • 0

I try to create my own websocket server. It works good with Safari and Opera, but doesn’t work with Firefox 8 and Chrome 15.

For setting connection i use such code

private static void Response(Socket client, string secKey)
{
   string guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
   SHA1 sha = new SHA1CryptoServiceProvider();
   byte[] hash = sha.ComputeHash(Encoding.ASCII.GetBytes(secKey + guid));
   string acceptKey = Convert.ToBase64String(hash);

   client.Send(Encoding.UTF8.GetBytes("HTTP/1.1 101 Switching Protocols" +   Environment.NewLine));
   client.Send(Encoding.UTF8.GetBytes("Upgrade: WebSocket" + Environment.NewLine));
   client.Send(Encoding.UTF8.GetBytes("Connection: Upgrade" + Environment.NewLine));
   client.Send(Encoding.UTF8.GetBytes("Sec-WebSocket-Accept: " + acceptKey + Environment.NewLine));
}

And for sending messages this one:

var mess = Encoding.UTF8.GetBytes(DateTime.Now.ToString()); 
item.Send(new byte[] { 129 });
item.Send(new byte[] { (byte)mess.Length });
item.Send(mess);

Can anybody help me and point out my mistakes?

  • 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-27T10:35:02+00:00Added an answer on May 27, 2026 at 10:35 am

    That code is only for Firefox 8 and Chrome 15 and greater. So I assume your working code with earlier browsers is different than what you posted since they have a different wire format.

    There are several issues with your code:

    • You need to pick and send back a protocol if the browser sends a protocol header (which it probably will).
    • You need to send a carriage return + line feed after each header (CR+LF, ‘\r\n’, 0x0D0A).
    • After the final header you need to send an additional carriage return + line feed (i.e. ‘\r\n\r\n’) to indicate completion of the handshake.

    Your send algorithm is also overly simplistic (although should work for you example). If the length of the message is more than 126 bytes then you must encode the length into multiple bytes of the frame header.

    Also note that for receiving frames, you will need to unmask the payload. The first four bytes of the payload are the masking values. You need to XOR these values to the following payload values. As described in the spec:

    j                   = i MOD 4
    transformed-octet-i = original-octet-i XOR masking-key-octet-j
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to create an own list type in haskell but, my implementation contains
I try to create my own helper but face a problem. First i create
I try to create an array of Integers (i tried with own object but
I want to try create something like Zend's Server Pagecache. What I want to
I try to create my own capcha (ctrlCapcha :UserControl) and I would like to
I try to create my own application bar in my app based on StackPanel.
So I try to create my own window system (because I want to have
I try to create options menu in a TabActivity. But instead of it I
i've been unsuccessfully attempting to create my own undo/redo classes that work well with
I read this http://developer.android.com/resources/tutorials/notepad/index.html and now try to create my own simple example. For

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.