1748084 Members
5379 Online
108758 Solutions
New Discussion юеВ

Bind in Client Process

 
Alfonso_15
Advisor

Bind in Client Process

Good Morning:
Usually, in Socket (Stream Connection) the instruction BIND is used for assign the Listening Port for a Server Process. Can I use Bind also for the Client Process: I means, The client process always uses the same port for connect to the server?
Thanks in advance for the guide.
alfonsoarias
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Bind in Client Process

BIND uses port 53 be default.

As with anything else this can be changed.

If you have a firewall blocking port 53 between your server and your client, it won't be able to connect.

You can check the /etc/service table for possible conflicts or problems.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Tomek Gryszkiewicz
Trusted Contributor

Re: Bind in Client Process

Steven,
i dont think it is about BIND (named) :)

Alfonso,
If the server is listening on the some port, client should connect to this port. Client side port number depends on system, it is always >1024.
Example:
serwer is listening on port 80. Client is connecting to this port from the other machine - and the client's port is - for example - 23456 (it it first free port on clients system, i think).
Alfonso_15
Advisor

Re: Bind in Client Process

Tomek. Thanks. Is rigth what you say. My question is if I can force my clien process for connect with the server using always the port 23456 , like in the server side I fix port 80 for always listen the request.
Thanks again for any guide.
alfonsoarias
Tomek Gryszkiewicz
Trusted Contributor

Re: Bind in Client Process

No, you cannot. Client's ports depends on system. BTW - What for? I cannot see the reason to set client's port permanently...
Steven Gillard_2
Honored Contributor

Re: Bind in Client Process

Yes, this is possible - lots of apps out there do it because it makes firewall configuration easier (Openview Operations for example).

However, if you always use the same port you'll only be able to have one client connection from each host. If you attempt a second connection while the first is still established, you'll receive an EADDRINUSE error from the connect() system call. If you need more than one connection you will need to make a range of ports available, and continue calling bind() for each port in the range until one succeeds.

Also be careful of TIME_WAIT sockets - these can also prevent the connection from succeeding. Make sure you set the SO_REUSEADDR socket option with setsockopt() before issuing the bind() call.

Regards,
Steve