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

The Archive Base Latest Questions

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

I’m trying to implement my own websocket server and am running into a bit

  • 0

I’m trying to implement my own websocket server and am running into a bit of trouble with the onmessage function in the JavaScript. It just won’t fire! I put an alert into it to trigger whenever it was called and the alert never comes up. I’ve tried on both firefox and chrome to no avail.

As far as I can tell, my server is sending the correct message as well, when I translate it into hex, it matches perfectly with the example in section 5.7 of the documentation here:

http://datatracker.ietf.org/doc/rfc6455/?include_text=1

So I’m not entirely sure what I’m doing wrong. The handshake works fine and so does the close. Here is my code for sending a message currently:

formatted_bytes = []
formatted_bytes.append( 129 )

message_bytes = bytearray( message )

data_start = 0

if ( len( message_bytes ) <= 125 ):
    formatted_bytes.append( len( message_bytes ) )
    start = 2

for byte in message_bytes:
    formatted_bytes.append( byte )

client_socket.send( bytes( formatted_bytes ) )

The server is written in python, forgot to mention that.

  • 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:35:46+00:00Added an answer on June 11, 2026 at 12:35 am

    This is the same answer as for your other question: Compressed bit must be 0 when sending a message to websocket client

    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

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.