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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:00:46+00:00 2026-05-22T23:00:46+00:00

I have a bytearray consisting of data received from a WebSocket-client. The data I

  • 0

I have a bytearray consisting of data received from a WebSocket-client. The data I have can be either 1 receive, or buffered data + the last receive. This depends on weather or not there were any data buffered.

Now, there are really 3 possible things that should happen when data is received, and they are as following (note, this is after I’ve concatenated the received data with the buffer):

  1. A partial message has been received: The client started to transmit a message, and only parts of the message (the beginning) has gotten trough yet. The data I’ve received needs to be buffered until the rest is received.
  2. A whole message has been received: The client has transmitted a whole message. An event should be fired with the message.
  3. A close-signal has been received: The client has sent a request to close the signal.

Now, there is no good reason as to why not several of these should happen at once (for instance, 1 and a half message is received, or 1 message and the close-signal is received). Messages in websocket are framed with the bytes 0x00 and 0xFF, in other words, incoming messages looks like this: 0x00,...binary UTF8 data,0xFF,0x00,...binary UTF8 data,0xFF, and the end signal looks like this: 0xFF,0x00. Now, what I need is an efficient way of taking the incoming data-stream and split it up into messages or the end-signal. I’ve never worked with framed data like this before, so I’m not sure how to do it efficiently. What I would like is more or less a function that takes in the binary data as an array, and returns the messages (as binary data without the frame) or the close-flag, and a byte-array with the data to be buffered. The important thing is that it is fast and don’t consume too much unnecessary memory. Or if you got some links that might help me to solve this issue, I’ll take them too gladly.

  • 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-22T23:00:47+00:00Added an answer on May 22, 2026 at 11:00 pm

    Your close-signal is just an empty message, not really a special case.

    So what you have is a mismatch between segments over the line and interpreted messages.

    It doesn’t look that hard, you have to extract sequences between 0x00 and 0xFF from a stream of bytes. You will need a buffer that is bigger than the biggest message, you will have to scan all incoming bytes and extract complete messages and move the remainder ‘down’ the buffer.

    You will also need:

    • to verify that your UTF8 data can not contain 0x00 or 0xFF, I’m not sure this is true
    • handle the case that 0xFF is followed by something else than 0x00
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to retrieve first bit from 1 byte. For this i stored whole
How can I convert a ByteArray to string. The toString() is not working as
I'm using system.net.mail and have a textbox that users can enter their email address
I'm stuck on creating a class architecture to do this: I have very many
I have a secret key that was sent to me as a file so
Hiho, i have to copy an inputstream. And after a bit of searching in
I am currently stuck with this problem of displaying an image using HtmlHelper class.
This is sort of a two part question. I'm building a flash image viewer
I am trying to save some images from Flash to Php by sending a
I am attempting to retrieve the ASPXAUTH cookie programmatically without success. A similar question

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.