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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:17:22+00:00 2026-06-15T09:17:22+00:00

I was looking at Create "Hello World" WebSocket example and began trying to adapt

  • 0

I was looking at Create "Hello World" WebSocket example and began trying to adapt this to send a custom message over the WebSocket that’s entered at the console, but I’m having a few issues understanding the code.

My question is what is the correct way to encode my own message so that it can be sent correctly based on the answer I linked above

client.Send(my-own-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-15T09:17:23+00:00Added an answer on June 15, 2026 at 9:17 am

    You should really go to the source. The Websocket specification is actually fairly straightforward to read, and it tells you exactly how your messages should be formatted.

    But in short, and assuming you’ve already completed the initial handshake establishing the connection, here is what data a Websocket frame should contain:

    • an opcode, a single byte with the value 0x81 if the message is formatted as UTF-8 text, and 0x82 if the message is binary data (note that a couple of browsers do not support the latter)
    • a length field of one or more bytes, describing the length of the message. The most significant bit of the first byte must be set on messages sent by the client (it indicates that the payload is masked, which must be done on client-to-server messages, and must not be done on server-to-client messages). The length field can have a variable length: If the length is below 126 bytes, it is simply encoded as a single byte (with the most significant bit reserved to indicate masking, as mentioned before). If the length is less than 65KB, the 7 available bits of the first byte take the value 126, and the two subsequent bytes contain the length as a 16-bit integer. Otherwise, the 7 bits of the first byte take the value 127, and the subsequent 8 bytes contain the length as a 64-bit integer.
    • a 4-byte masking key, which must be picked randomly for every message
    • and finally, the actual message you wish to send. This must be masked using the masking key, simply by XOR’ing each byte with a byte of the masking key. (byte i of the message should be XOR’ed together with the i%4th byte of the masking key).

    Do this, and you’ve created a valid websocket frame containing either UTF8 text or raw binary data. As you can see, there are a few steps involved, but each is relatively straightforward. (And again, please check with the RFC I linked to, because I just wrote all of this from memory, so there might be minor inaccuracies)

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

Sidebar

Related Questions

I looking to create a custom calender with Zend Framework, I am hoping that
I'm looking to create something like in this image. Each block would have an
I'm search a component/possibility that allows me to create such a nice looking "Component
I'm trying to create a page that allows a user to change the "look
I'm trying to create a constructor for a custom type, but for some reason,
I am trying to create an app that can "Purposely" consume RAM as much
I am trying to create a sort of "window" effect where the div positioned
"My Location" in Google Maps javascript API This question was asked over half a
I'm trying to create a custom JSP tag that uses other custom tags. My
My question is how to create variables "on the fly". I'm trying to generate

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.