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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:52:37+00:00 2026-06-12T10:52:37+00:00

I wanted to know the exact function of bind() in TCP. What does it

  • 0

I wanted to know the exact function of bind() in TCP. What does it mean by ‘binding’ a local address to the socket? If it’s assigning a port number to the socket, then why don’t we use it in the client? I know that port is assigned by OS automatically in the client side, but I’m not getting the big picture of how all of this works.

After bind(), we listen(). How is the bind related to listen()? Will the listen() know that bind() has been executed? If so, what changes does bind() make so that it is known? I mean, how does returning zero for successful execution help?

I’ve gone through many definitions, but no where I could get all of this in detail. So if anyone can please explain this to me, I will be grateful.

  • 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-12T10:52:38+00:00Added an answer on June 12, 2026 at 10:52 am

    It assigns the “local” end’s port number.

    For a server socket, this is the ultimate way to go – it is exactly what is needed: have your socket be bound to port 80 for a web server, for example.

    For a client socket, however, the local address and port is normally not of importance. So you don’t bind(). If the server restricts its clients to maybe have a certain port number, or a port number out of a given range, you can use bind() on client side as well.

    On the other hand, you might as well be able to listen() on a socket where you haven’t called bind() (actually I’m not sure about that, but it would make sense). In this scenario, your server port would be random, and the server process would communicate its port via a different means to the client. Imagine a “double-connection” protocol such as FTP, where you have a control connection and a data connection. The port the data connection listens on is completely arbitrary, but must be communicated to the other side. So the “automatically determined port” is used and communicated.

    One example in Python:

    import socket
    s = socket.socket() # create your socket
    s.listen(10) # call listen without bind
    s.getsockname() Which random port number did we get?
    # here results in ('0.0.0.0', 61372)
    
    s2 = socket.socket() # create client socket
    s2.connect(('localhost', 61372)) # connect to the one above
    s3, x = s.accept() # Python specific use; s3 is our connected socket on the server side
    s2.getpeername()
    # gives ('127.0.0.1', 61372)
    s2.getsockname()
    # gives ('127.0.0.1', 54663)
    s3.getsockname()
    # gives ('127.0.0.1', 61372), the same as s2.getpeername(), for symmetry
    s3.getpeername()
    #gives ('127.0.0.1', 54663), the same as s2.getsockname(), for symmetry
    #test the connection
    s2.send('hello')
    print s3.recv(10)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of a way to allow multiple users work from the exact
I am using System.Net.Sockets Socket class to receive UDP datagrams. I wanted to know
I wanted know how the kernel is providing memory for simple C program .
Wanted to know if there was a way one could query shelveset details from
Wanted to know if someone had a suggestion on code or maybe there's a
I wanted to know about Data Type implementation in PHP so I need a
I wanted to know that if I am doing correctly, regarding retain and release
I wanted to know if it's possible to derive a method to generate a
Just wanted to know how i would replace sitename.com with sitename2.com whenever a user
I wanted to know how to represent a whitespace character in C#. I found

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.