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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:24+00:00 2026-05-26T09:54:24+00:00

I’m trying to develop a webchat with HTML5 websocket (with hybi-17 protocol) but I’ve

  • 0

I’m trying to develop a webchat with HTML5 websocket (with hybi-17 protocol) but I’ve some problems with chars decoding.
This is what I send through the client (user-agent: Firefox 7):

var socket = new MozWebSocket ('ws://localhost/server.php');
socket.onopen = function () {
  alert ('Opened!');
}

Then, I send these data:

socket.send ('Hello');
socket.send ('World');

And this is the server-side code:

$bytes = @socket_recv ($socket, $buffer, BUFSIZE, 0);

if (($bytes == 0) || ($bytes == 2)) {
  this->disconnect ($socket);
}
else {
  echo $buffer;
}

While this is the data recevied echoed:

��6S~g?Y (Hello)
���~����� (World)

As you can see, the socket is opened and data travels from the client to the server.
The server works with PHP5 and uses normal socket functions to build the connection.

How can I decode that unreadable string in a human readable one?

Thanks in advance.

  • 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-26T09:54:25+00:00Added an answer on May 26, 2026 at 9:54 am

    You have made one of the most common errors people make when they first start writing code that uses TCP — you forgot to implement the protocol!

    In your case, you forgot it in the server. The client already has a WebSocket implementation, and you request it by creating a ‘MozWebSocket’ object. The WebSocket specification says, “Each frame starts with a 0x00 byte, ends with a 0xFF byte, and contains UTF-8 data in between.” Where’s the code in the server to find the start of a frame and the end of a frame? Where the code to discard the 0xFF byte?

    You actually have to implement the protocol. The protocol specification tells you how to decode the received data. (In your case, the data you are seeing as junk is most likely part of the protocol handshake — the part that looks like ^n:ds[4U in this description of the handkshake phase.)

    I’m pretty sure your method of invoking a PHP script to handle the WebSocket call through the web server will not work. That is, unless your web server knows how to do this — WaterSpout and phpdaemon do.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
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.