Skip to content

Instantly share code, notes, and snippets.

@Srushtika
Created November 16, 2018 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Srushtika/153c9a34262fa0bad897c2ed8a4f6170 to your computer and use it in GitHub Desktop.
Save Srushtika/153c9a34262fa0bad897c2ed8a4f6170 to your computer and use it in GitHub Desktop.
WebSockets server tutorial
const crypto = require('crypto');
function generateAcceptValue (acceptKey) {
return crypto
.createHash('sha1')
.update(acceptKey + '258EAFA5-E914–47DA-95CA-C5AB0DC85B11', 'binary')
.digest('base64');
}
@Robdebert
Copy link

@Srushtika The hash is generated by this function in my code and it is added to the response-headers.
But the client (google chrome) says: "failed: Error during WebSocket handshake: Incorrect 'Sec-WebSocket-Accept' header value"

Do you know what that means?

@Kolahzary
Copy link

@Robdebert @Srushtika
.update(acceptKey + '258EAFA5-E914–47DA-95CA-C5AB0DC85B11', 'binary')
should be
.update(acceptKey + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11', 'utf8')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment