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

  • Home
  • SEARCH
  • 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 8499689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:44:08+00:00 2026-06-11T00:44:08+00:00

I’m writing a websocket server in python, and I’ve run into a problem when

  • 0

I’m writing a websocket server in python, and I’ve run into a problem when sending messages back to the client. Using chrome’s javascript console, I can get as far as finding this error message:

Compressed bit must be 0 if no negotiated deflate-frame extension

But farther than that I can’t find any documentation on what that actually means. You can find the start of this problem (and the code) here. I’m kind of at a loss. I’ve tried playing around with the first byte, changing it to all 0’s, but according to this, the second bit, which is 0 in my case, should be the "compressed bit" if this documentation is correct;

"One reserved bit RSV1 in the WebSocket frame
header is allocated to control application of compression for each
message."

So I’m not entirely sure where to go from here. In firefox the error is simply a "The connection to ws://localhost:8080/ was interrupted while the page was loading." error.

EDIT: Here is the parse code when receiving a message:

def parse( self, data, client_socket ):
    display_server_message( "Received message:\n%s" % str( data ) )
    byte_array = bytearray( data )
    mask = []

    message_string = ""
    for i in range( 0, len( byte_array ) ):
        b = byte_array[ i ]
        if i > 0 and i < 2:
            b = b & 0b01111111
        if i > 1 and i < 6:
            mask.append( byte_array[ i ] )
        if i > 5:
            b = b ^ mask[ (i - 2) % 4 ]
            message_string = message_string + chr( b )

    display_server_message( "Decoded Message:\n%s" % message_string )
    if ( message_string == "a test message" ):
        time.sleep( 5 )
        self.send_message( "Hello, how are you?", client_socket )


    pat = re.compile( "Sec-WebSocket-Key: (\S+)", re.MULTILINE )

    for match in pat.findall( data ):
        magic_string = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

        message = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: %s\r\n\r\n" % base64.standard_b64encode( hashlib.sha1( match + magic_string ).digest() )

        client_socket.send( message )
        display_server_message( "Message Sent:\n%s" % message )
  • 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-06-11T00:44:10+00:00Added an answer on June 11, 2026 at 12:44 am

    This is the same answer as for your other question: WebSocket onmessage not firing

    You’re problem is that you are using the bytes function in python 2.X but expecting it to work the way it does in python 3.X

    python2.6.6:

    >>> bytes([129, 19])
    '[129, 19]'
    

    python 3:

    >>> bytes([129, 19])
    b'\x81\x13'
    

    By replacing the send with the following in your server code it works for me in python2.X:

    client_socket.send( "".join( [chr(c) for c in formatted_bytes] )
    

    A couple of other notes:

    • The code you linked to is adding 1 to the message length which is incorrect.

    • You should really have the handshake code separate from the normal message parsing code. If somebody happened to send a message which contained “Sec-WebSocket-Key: ” you would end up corrupting the stream by sending a raw handshake back again.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.