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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:34:18+00:00 2026-05-11T05:34:18+00:00

The socket API is the de-facto standard for TCP/IP and UDP/IP communications (that is,

  • 0

The socket API is the de-facto standard for TCP/IP and UDP/IP communications (that is, networking code as we know it). However, one of its core functions, accept() is a bit magical.

To borrow a semi-formal definition:

accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.

In other words, accept returns a new socket through which the server can communicate with the newly connected client. The old socket (on which accept was called) stays open, on the same port, listening for new connections.

How does accept work? How is it implemented? There’s a lot of confusion on this topic. Many people claim accept opens a new port and you communicate with the client through it. But this obviously isn’t true, as no new port is opened. You actually can communicate through the same port with different clients, but how? When several threads call recv on the same port, how does the data know where to go?

I guess it’s something along the lines of the client’s address being associated with a socket descriptor, and whenever data comes through recv it’s routed to the correct socket, but I’m not sure.

It’d be great to get a thorough explanation of the inner-workings of this mechanism.

  • 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. 2026-05-11T05:34:19+00:00Added an answer on May 11, 2026 at 5:34 am

    Your confusion lies in thinking that a socket is identified by Server IP : Server Port. When in actuality, sockets are uniquely identified by a quartet of information:

    Client IP : Client Port and Server IP : Server Port

    So while the Server IP and Server Port are constant in all accepted connections, the client side information is what allows it to keep track of where everything is going.

    Example to clarify things:

    Say we have a server at 192.168.1.1:80 and two clients, 10.0.0.1 and 10.0.0.2.

    10.0.0.1 opens a connection on local port 1234 and connects to the server. Now the server has one socket identified as follows:

    10.0.0.1:1234 - 192.168.1.1:80   

    Now 10.0.0.2 opens a connection on local port 5678 and connects to the server. Now the server has two sockets identified as follows:

    10.0.0.1:1234 - 192.168.1.1:80   10.0.0.2:5678 - 192.168.1.1:80 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in C++, using the standard socket API, running on Ubuntu
I am in the process of writing a TCP server using Berkely SOCKET API
I'm new to node.js but I know it has a great socket API called
I want to create a TCP socket that listens only on a specific interface
I'm doing a simple UDP send using Node's inbuilt datagram UDP socket : http://nodejs.org/docs/v0.3.1/api/dgram.html
Boost asio has such socket connect api . I have such simple code: try
When creating a TCP client using the socket API, a port is used on
I can't come up with the exact socket api,but I remember that there is
I've been working with the .NET 3.5 asynchronous socket API and found that ll
I have a worker thread that is listening to a TCP socket for incoming

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.