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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:47:55+00:00 2026-05-27T19:47:55+00:00

For a TCP server with following structure: main(){ socket(); bind(); listen(); while(1){ accept(); fork();

  • 0

For a TCP server with following structure:

main(){
    socket();
    bind();
    listen();
    while(1){
       accept();
       fork();
       if(child)
          Process;
    }
}

It creates a new socket for each client and communicates with all clients using the same port. Thus, all sockets bind to the same port.

I came across following comments when reading the kernel code (2.6.33.5):

48/* There are a few simple rules, which allow for local port reuse by
49 * an application.  In essence:
50 *
51 *      1) Sockets bound to different interfaces may share a local port.
52 *         Failing that, goto test 2.
53 *      2) If all sockets have sk->sk_reuse set, and none of them are in
54 *         TCP_LISTEN state, the port may be shared.
55 *         Failing that, goto test 3.
56 *      3) If all sockets are bound to a specific inet_sk(sk)->rcv_saddr local
57 *         address, and none of them are the same, the port may be
58 *         shared.
59 *         Failing this, the port cannot be shared.
60 *

So, for the TCP server above, is it the third rule which it matches?

  • 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-27T19:47:55+00:00Added an answer on May 27, 2026 at 7:47 pm

    There are 1 plus N sockets playing in this game.

    1 The listening socket, which was passed to bind() and listen(). Only this socket is bound to the port on which the server listens.

    2 All the N connected sockets created by the N ‘processes’ of the clients connecting to the server, and being returned by accept(). Those sockets are serving the connections to the clients. Such sockets do not listen in the sense the listening socket does.

    The rules you quoted apply to the listening socket only.

    So if you only run one instance of your server the third rule does not apply, as it bind()s only one socket to listen() on the server’s port.

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

Sidebar

Related Questions

I am in the process of writing a TCP server using Berkely SOCKET API
I have a TCP socket server and I want to do the following w/o
I need a sample application of the following scenario 1) IOCP TCP Server capable
I am trying to create a tcp synchronous server. My main thread would create
I have a class that encapsulates tcp socket communications with a server. For each
I am using node.js to build a TCP server and I got the following
I have implemented an asynchronous TCP server that is spawned by another process. It
I put a TCP server and client code in PIC controller. Now just wanted
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have written a secure TCP server in .NET. This was basically as simple

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.