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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:06:44+00:00 2026-05-28T01:06:44+00:00

On the client side: int clientSocketFD; if ((clientSocketFD = socket (PF_INET, SOCK_STREAM, 0)) ==

  • 0

On the client side:

    int clientSocketFD;
    if ((clientSocketFD = socket (PF_INET, SOCK_STREAM, 0)) == -1)
    {
        perror ("socket (): ");
        exit (1);
    }

The client is one and servers are many. Do I have to issue the socket() system call each time a new server needs to get connected to the same client?

Please explain WHY.

  • 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-28T01:06:45+00:00Added an answer on May 28, 2026 at 1:06 am

    Yes – you need one socket for each connection.

    A socket is a client IP address + client port + server IP address + server port combination. If a client is talking to multiple servers, it is using multiple ports on the client machine.

    Each time you connect() a socket, you are allocating a new port.

    You can specify what client port you want to use by bind()-ing to the port number. Otherwise, the operating system chooses a port for you. This is called an “ephemeral” port.

    If a server is talking to multiple clients, there is a socket created for each client by the call to accept().

    An analogy that I remember:

    Imagine that you have an apartment building with many people living in it. There are mailboxes available out front for the people in the apartment to use.

    The apartment building corresponds to a computer, the people in the apartment correspond to programs running on the computer, and the mailboxes are ports. Each port can be used by only one application at a time as its private in/out box.

    A socket is a link between a single mailbox on one building to a single mailbox on another. It is the “to” and “from” address. The socket API uses a socket to know where to send packets, and what reply address to put on the packet. A socket may even link two mailboxes on the same building.

    A single application on the computer may be using many ports, and they may even be connected to the same port on the same remote computer. Therefore the socket information (IP address + port on both connected machines) is needed to eliminate any ambiguity over the destination and return addresses.

    Likewise multiple applications on a single computer may be connected to the same port on the same server and sending requests, but the server sends its response to the right application because the return addresses have different port numbers.

    A socket has the same 4 pieces of information on both communicating machines.

    In client/server communication for a Web server, many clients are connected to one server port. So the sockets all look like { client(n) IP, client(n) port, server IP, server port 80 }.

    As @DavidGelhar said it would theoretically be possible for multiple servers to be communicating with the same port on the client, because the socket information specifies the correct server address to send to. However you cannot connect() a single port multiple times. The servers could all connect() to that same client port, but then they can no longer be called servers 🙂

    Basically, a socket is just a 4-piece data structure that the socket API uses to know where to send data to, and what return address to put on the data. Likewise a “port” is just a number used as an address to target a specific application on a machine, it is by no means an actual hardware object.

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

Sidebar

Related Questions

Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have some client side code that uploads an Outlook email to a document
I am creating a client side swing app that will have data provided by/from
I am using java sockets for communication. On the client side I have some
I am calling a specific WebMethod from client side like this: function openSmallPopup(int) {
I have an old client side application that is writing to named pipes using
I have a server side class which I make available on the client side
I'm trying to get one side to send an error message to client, but
I have enabled unobtrusive client side validation in my app, and I have (something
I have a client side gridview data and I want to insert gridview data

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.