I\'ve not a clear idea about when I have to use the bind() function. I guess it should be used whenever I need to receive data (i.e. recv() or recvfrom() functions) whether I\'m
bind()
is useful when you are writing a server which awaits data from clients by "listening" to a known port. With bind()
you are able to set the port on which you will listen()
with the same socket.
If you are writing the client, it is not needed for you to call bind()
-- you can simply call recv()
to obtain the data sent from the server. Your local port will be set to an "ephemeral" value when the TCP connection is established.