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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:23:30+00:00 2026-05-22T17:23:30+00:00

How do I implement something similar to the HTTP Basic authentication, in a TCP

  • 0

How do I implement something similar to the HTTP Basic authentication, in a TCP server written for Node.JS ? The code for a basic TCP server is the following:

// Load the net module to create a tcp server.
var net = require('net');

// Setup a tcp server
var server = net.createServer(function (socket) {

  // Every time someone connects, tell them hello and then close the connection.
  socket.addListener("connect", function () {
    console.log("Connection from " + socket.remoteAddress);
    socket.end("Hello World\n");
  });

});

// Fire up the server bound to port 7000 on localhost
server.listen(7000, "localhost");

// Put a friendly message on the terminal
console.log("TCP server listening on port 7000 at localhost.");
  • 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-22T17:23:30+00:00Added an answer on May 22, 2026 at 5:23 pm

    While there are several ways to provide authentication over a TCP connection, all require some form of "protocol" being an agreed-upon communications grammar/syntax.

    For example, in the Simple Mail Transport Protocol, the following conversation occurs (where S: and C: designate lines provided by the SMTP server and email client, respectively):

    S: 220 server.example.com
    C: HELO client.example.com
    S: 250 server.example.com
    C: MAIL FROM:<sender@example.com>
    S: 250 2.1.0 sender@example.com... Sender ok
    C: RCPT TO:<recipient@example.com>
    S: 250 recipient <recipient@example.com> OK
    C: DATA
    S: 354 enter mail, end with line containing only "."
    C: full email message appears here, where any line
    C: containing a single period is sent as two periods
    C: to differentiate it from the "end of message" marker
    C: .
    S: 250 message sent
    C: QUIT
    S: 221 goodbye
    

    In replies from the server, the initial numeric value indicates the success or failure of the requested operation, or that the reply contains an informational message. Using a three digit numeric value allows for efficient parsing as all replies beginning with 2xx indicate success, 3xx are informational, 4xx indicate protocol errors, and 5xx are reserved for server errors. See IETF RFC 5321 – https://www.rfc-editor.org/rfc/rfc5321 for the full protocol.

    So in your specific case, you might consider something as simple as:

    [connect to TCP server]
    S: ?                    # indicates the server is ready for authorization
    
    C: username password   # send authentication credentials
    

    The server would then reply with:

    S: !                    # indicates successful authentication and 
                            # that server is ready for more commands 
    

    Or

    S: ?                    # indicates authentication failure
    

    If too many failed attempts to authenticate are seen, the server might sever the connection to reduce the potential for abuse, such as DDOS attacks.

    Once authenticated, the client could send:

    C: >                    # begin streaming
    

    Or any other command you which to support.

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

Sidebar

Related Questions

I'm trying to implement something similar to what http://www.ancestry.com has, but I'm not sure
In my own server control, I would like to implement something similar to the
I'm about to implement something similar to : http://doc.qt.nokia.com/latest/itemviews-simpletreemodel.html I have a type, aosl::Object,
I would like to implement something similar to a c# delegate method in PHP.
I need to implement something similar to wikilinks on my site. The user is
I would like to implement something similar to 37Signals's Yellow Fade effect. I am
Is there any way to implement something similar to Chatroulette without using Flash or
I'm trying to implement something similar to a cart where you can drop items
I wonder how do they implement the bone animation in the flash game http://www.foddy.net/athletics.swf
I am trying to implement something similar to the flight control game. There will

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.