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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:46:56+00:00 2026-05-23T09:46:56+00:00

im paging my php websocket server to node.js but i don’t understand, why my

  • 0

im paging my php websocket server to node.js but i don’t understand, why my handshake fails! Here is my code:

var msg = data;
//console.log(msg);

tmp = msg.match(/\r\n\r\n(.*?)$/);
if(tmp) code = tmp[1];

tmp = msg.match(/GET (.*?) HTTP\/1.1/);
if(tmp) res = tmp[1];

tmp = msg.match(/Sec-WebSocket-Key1: (.*?)\r\n/);
if(tmp) key1 = tmp[1];

tmp = msg.match(/Sec-WebSocket-Key2: (.*?)\r\n/);
if(tmp) key2 = tmp[1];

tmp = msg.match(/Host: (.*?)\r\n/);
if(tmp) host = tmp[1];

tmp = msg.match(/Origin: (.*?)\r\n/);
if(tmp) origin = tmp[1];

tmp = msg.match(/Upgrade: (.*?)\r\n/);
if(tmp) upgrade = tmp[1];

tmp = msg.match(/Connection: (.*?)\r\n/);
if(tmp) connection = tmp[1];

tmp = key1.match(/[0-9]/g);
num1 = parseInt(tmp.join(''));

tmp = key2.match(/[0-9]/g);
num2 = parseInt(tmp.join(''));

tmp = key1.match(/\s/g);
spa1 = tmp.length;

tmp = key2.match(/\s/g);
spa2 = tmp.length;

part1 = num1/spa1;
part2 = num2/spa2;

var md5 = crypto.createHash('md5');

test1 = String.fromCharCode(part1 >> 24 & 0xFF, part1 >> 16 & 0xFF, part1 >> 8 & 0xFF, part1 & 0xFF);
md5.update(test1);  

test2 = String.fromCharCode(part2 >> 24 & 0xFF, part2 >> 16 & 0xFF, part2 >> 8 & 0xFF, part2 & 0xFF);
md5.update(test2);

md5.update(code);

var fin = md5.digest('binary');

var out = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n"+'Upgrade: '+upgrade+"\r\n"+'Connection: '+connection+"\r\n"+'Sec-WebSocket-Origin: '+origin+"\r\n"+'Sec-WebSocket-Location: ws://'+host+res+"\r\n\r\n"+fin;

console.log(out);
socket.write(out, 'utf8');

If someone has an idea, I would be amused 🙂 Tryed this code with example given in v76 spec of handshake method and its ok there.

  • 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-23T09:46:57+00:00Added an answer on May 23, 2026 at 9:46 am

    You can refer phpwebsocket for more information.

    And in the latest WebSocket protocol version [draft-ietf-hybi-thewebsocketprotocol-09, the handshake mechanism has been updated, there will be only one “Sec-WebSocket-Key”, you can learn more about the revised handshake mechanism from my article: http://www.codeproject.com/KB/HTML/Web-Socket-in-Essence.aspx

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

Sidebar

Related Questions

I'm following this tutorial here: http://brenelz.com/blog/implementing-paging-using-php-and-jquery/ Here is what I have: http://eataustineat.com/testingfolder/ I've encountered
here is my paging code: function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET['page']) &&
I got some legacy code that has this: <?PHP if(isset($_GET['pagina'])==homepage) { ?> HtmlCode1 <?php
i have one php page with paging option i use follwoing sql statement to
how do i implement paging on xml data which is being called through php.
i'm trying to implement paging in xml using this code and got around to
Please see below code snippt: <?php //Sets the update and indicator elements by DOM
I am working on paging in PHP I need it to work on any
I am trying to implement paging in PHP, using Json. I need the data
I have been playing with server side sorting/paging using YUI DataTable, and everything is

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.