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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:15:20+00:00 2026-06-04T16:15:20+00:00

I want to provide a meaningful error to the client when too many users

  • 0

I want to provide a meaningful error to the client when too many users are connected or when they’re connecting from an unsupported domain, so…

I wrote some WebSocket server code:

var http = require('http');
var httpServer = http.createServer(function (request, response)
{
    // i see this if i hit http://localhost:8001/
    response.end('go away');
});

httpServer.listen(8001);

// https://github.com/Worlize/WebSocket-Node/wiki/Documentation
var webSocket = require('websocket');
var webSocketServer = new webSocket.server({ 'httpServer': httpServer });

webSocketServer.on('request', function (request)
{
    var connection = request.reject(102, 'gtfo'); 
});

And some WebSocket client code:

var connection = new WebSocket('ws://127.0.0.1:8001');
connection.onopen = function (openEvent)
{
    alert('onopen');
    console.log(openEvent);
};
connection.onclose = function (closeEvent)
{
    alert('onclose');
    console.log(closeEvent);
}
connection.onerror = function (errorEvent)
{
    alert('onerror');
    console.log(errorEvent);
};
connection.onmessage = function (messageEvent)
{
    alert('onmessage');
    console.log(messageEvent);
};

All I get is alert('onclose'); with a CloseEvent object logged to the console without any status code or message that I can find. When I connect via ws://localhost:8001 the httpServer callback doesn’t come into play, so I can’t catch it there. The RFC suggests I should be able to send any status code other than 101 when there’s a problem, but Chrome throws an error in the console Unexpected response code: 102. If I call request.reject(101, 'gtfo'), implying it was successful I get a handshake error, as I’d expect.

Not really sure what else I can do. Is it just not possible right now to get the server response in Chrome’s WebSocket implementation?

ETA: Here’s a really nasty hack in the mean time, I hope that’s not what I have to end up doing.

var connection = request.accept(null, request.origin);
connection.sendUTF('gtfo');
connection.close();
  • 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-04T16:15:20+00:00Added an answer on June 4, 2026 at 4:15 pm

    I’m the author of WebSocket-Node and I’ve also posted this response to the corresponding issue on GitHub: https://github.com/Worlize/WebSocket-Node/issues/46

    Unfortunately, the WebSocket protocol does not provide any specific mechanism for providing a close code or reason at this stage when rejecting a client connection. The rejection is in the form of an HTTP response with an HTTP status of something like 40x or 50x. The spec allows for this but does not define a specific way that the client should attempt to divine any specific error messaging from such a response.

    In reality, connections should be rejected at this stage only when you are rejecting a user from a disallowed origin (i.e. someone from another website is trying to connect users to your websocket server without permission) or when a user otherwise does not have permission to connect (i.e. they are not logged in). The latter case should be handled by other code on your site: a user should not be able to attempt to connect the websocket connection if they are not logged in.

    The code and reason that WebSocket-Node allow you to specify here are an HTTP Status code (e.g. 404, 500, etc.) and a reason to include as a non-standard “X-WebSocket-Reject-Reason” HTTP header in the response. It is mostly useful when analyzing the connection with a packet sniffer, such as WireShark. No browser has any facility for providing rejection codes or reasons to the client-side JavaScript code when a connection is rejected in this way, because it’s not provided for in the WebSocket specification.

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

Sidebar

Related Questions

I want to provide my user with some meaningful error messages when network requests
I want to provide a progress bar for my users who upload very large
I want to provide feedback to a user when they enter something into a
I want to provide a set of filters for a user to pick from,
I want to provide a client with a third-party source with some details of
I want provide bonuses to users how have shared link to my android application.
I want to provide some dynamic content like an rss feed, so when they
I want to provide other sites with a banner from my site but I
I want sell some .NET library and I want provide edition with full source
I want to provide my colleagues with an interface (using Windows Forms or WPF)

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.