top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of "bind()" in TCP socket programming?

+1 vote
832 views

Is it right that it is used to bind Port number with IP?
If it is, then What is the need of binding it? and Why it is not present in UDP?
And also, What is the use of listen(5) ?
Does it mean that server can be connected maximum to 5 client? or it means that if server is busy with other client then 5 more client can be in queue.?
and also, What is the use of select() ?
As far as i know it is used when we want to monitor continuously input/output for that particular file descriptor.
is it correct?
If yes, then why it is used only when accepting connection request from multiple client.?

posted Jun 5, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Bind function "binds" a socket to an address, otherwise it doesn't know what address (ip-address/port pair) it should listen to.

It is not correct that we dont need to bind the UDP socket (Server side needs a bind while client is not). Check this http://www.programminglogic.com/sockets-programming-in-c-using-udp-datagrams/

answer Jun 5, 2015 by Salil Agrawal
Ok, Thanks, Sir
but there are few more questions in comments. can you please help in that?
Listen takes two parameters first is the socket ID and second is the length of the buffer which means how many pending connection possible which are not accepted.

PS: Please frame the query clearly so that an unknown person can understand. Its better to ask multiple question for multiple problem so that those are not missed.
Similar Questions
+2 votes

For An Example:
I have Socket-Programming where server is connected to 5 clients and it continuously sends and receives to all the clients.
Now, If one of the client looses the network or in whatever the case one of the client fails then master will also fail and because of it all other client will also be failed.

0 votes

is it for No of connection can be accepted?
or is it for no of client can be in queue while SFD is busy..?

i have kept 0 as an argument in listen, still it is taking 10 connection..
but if i remove listen then it is showing an error..

Can anybody please help in this?

Thanks in advance

+1 vote

In my testing, I found that when i send packets of bytes 1000-5000 bytes from my sender, they get assembled/bundled at receiver with sizes 8000-14000 bytes. I checked the wireshark capture to confirm this.

I have 2 questions:
1) Who bundles these packets in between, receiver receives these and I use select() to detect data and call recvmsg api ?.

2) When packets of lengths increase at receiver, I implemented partial reception so that 'recvmsg' returns partial data also. In this case after some time, recvmsg call returns EAGAIN with 0 bytes. The connection with peer is still up, because peer is still sending packets, why is recvmsg call returing error with EAGAIN ?.

...