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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:37:44+00:00 2026-05-30T04:37:44+00:00

I am writing a small WebSocket server application that should support both draft 17

  • 0

I am writing a small WebSocket server application that should support both draft 17 and older variations such as draft 00. I didn’t have any problems with the newest draft, but I cannot make the draft 00 client happy.

For testing purposes I used the example provided in the official (old) draft 00 docuemnt, page 7:

Sec-WebSocket-Key1: 18x 6]8vM;54 *(5:  {   U1]8  z [  8
Sec-WebSocket-Key2: 1_ tx7X d  <  nw  334J702) 7]o}` 0

Tm[K T2u

When calculating the keys by concatenating the digits and dividing by spaces count, I get the following two integers: 155712099 and 173347027 (the document has these two numbers as well).

Next, it says to:

  1. Convert them individually to Big Endian
  2. Concatenate the result in a string and append the last eight bits (Tm[K T2u).
  3. Create a 128 bits MD5 sum from the string produced in step 1 and 2.

Armed with this knowledge I’ve produced the following code:

#define BYTE    8
#define WORD    16

// Little Endian to Big Endian short
#define LE_TO_BE_SHORT(SHORT)\
    (((SHORT >> BYTE) & 0x00FF) | ((SHORT << BYTE) & 0xFF00))

// Little Endian to Big Endian long
#define LE_TO_BE_LONG(LONG)\
    (((LE_TO_BE_SHORT(LONG >> WORD)) | \
     ((LE_TO_BE_SHORT((LONG & 0xFFFF)) << WORD))))

uint num1 = LE_TO_BE_LONG(155712099);
uint num2 = LE_TO_BE_LONG(173347027);

QString cookie = QString::fromUtf8("Tm[K T2u");
QString c = QString::number(num1) + QString::number(num2) + cookie;

QByteArray data = c.toUtf8();
qDebug() << QCryptographicHash::hash(data, QCryptographicHash::Md5);

Here’s what I get:

←→»α√r¼??┐☺║Pa♠µ

And here’s what’s expected (again, based on the draft example)

fQJ,fN/4F4!~K~MH

On the other side, I’ve noticed that the wikipedia article does not mention anything about Endian conversion. I tried the above code without conversion (both wikipedia example and the example from the draft) and still cannot reproduce the expected result.

Anyone can point out what is the problem here?


EDIT:

I found this document has a better explanation of the protocol. It is a different draft (76) but is similar to 00 in terms of handshake.

  • 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-30T04:37:45+00:00Added an answer on May 30, 2026 at 4:37 am

    Finally with the help of fresh eyes from my colleagues, I figured out what I was doing wrong. Basically I was literally concatenating the two integers into a string. Instead I needed to concatenate the bytes:

    uint num1 = LE_TO_BE_LONG(155712099); // macros definition can
    uint num2 = LE_TO_BE_LONG(173347027); // be found in the question
    QString cookie = QString::fromUtf8("Tm[K T2u");
    
    QByteArray array;
    
    array =  QByteArray((const char*)&num1, sizeof(int));
    array += QByteArray((const char*)&num2, sizeof(int));
    array += QByteArray(cookie.toStdString().data(), cookie.length());
    
    qDebug() << QCryptographicHash::hash(array, QCryptographicHash::Md5);
    

    Make sure that you don’t use the overloaded constructor that does not take the size because Qt will crate a slightly larger array padded with garbage. At least that was in my case.

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

Sidebar

Related Questions

I have an application where I am reading and writing small blocks of data
While writing a small C# application for myself I realized that it would be
when writing small functions I often have the case that some parameters are given
Writing a small application in order to demonstrate certain functionality. I have an embedded
I'm currenty writing small application for image processing. However I have a big problem
I'm writing a small client application to communicate with a server. I open a
I am writing a small application with clock that sicplay date and time with
Coming from a PHP background, I'm used to writing small functions that return a
I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass
I'm writing a small application in VB.NET and I would like some of the

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.