Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What client-side situations need bind()?

I'm learning C socket programming. When would you use bind() on the client-side? What types of program will need it and why? Where can I find an example?

like image 245
friends Avatar asked Nov 07 '10 14:11

friends


People also ask

Is bind necessary in client side?

On the client side, you would only use bind if you want to use a specific client-side port, which is rare. Usually on the client, you specify the IP address and port of the server machine, and the OS will pick which port you will use.

Why do we need to call bind () in server code and not in the client code?

You only need to bind on the client if the server expects you to be coming from a specific port or port range. Some services only allow connections from port numbers less than 1024, those only bindable by the superuser, though that doesn't mean much these days now that everyone controls their own machine.

Why bind is not used in client side?

It's because client always have to connect to the server. Client can be called as slave and server is always the master. But server can speak to the client only if there is the particular code given such Buffered Inputstream. other wise it can't send any input to client even if there is a connection.

What is the use of bind () system call?

The bind() function binds a unique local name to the socket with descriptor socket. After calling socket(), a descriptor does not have a name associated with it. However, it does belong to a particular address family as specified when socket() is called. The exact format of a name depends on the address family.


2 Answers

On the client side, you would only use bind if you want to use a specific client-side port, which is rare. Usually on the client, you specify the IP address and port of the server machine, and the OS will pick which port you will use. Generally you don't care, but in some cases, there may be a firewall on the client that only allows outgoing connections on certain port. In that case, you will need to bind to a specific port before the connection attempt will work.

like image 194
Graeme Perrow Avatar answered Sep 30 '22 01:09

Graeme Perrow


An example would be the data connection of an active FTP connection. In this case, the server connects from its port 20 to the IP and port specified by a PORT or EPRT command.

like image 40
ninjalj Avatar answered Sep 30 '22 02:09

ninjalj