binding a socket

Hi All:

I’m writing a Server under qnx, when I try to bind a socket, I
specfically try to bind to
port #2000, and in my Client side, I try to connect to port #2000.
However… bind function
often fails when it tries to bind to port #2000. This function always works
if i let it bind
to a open port randomly, and pass in that port # to my client’s program as
an arg. But
I can’t ask the customer to entered the port # printed out by t he server
program in the shell
and pass it in in order to start my client program. Is there any more
elegant way of handling this?
Maybe a higher port #?

Another question. how would the client know when the Server is ready and
starting to listen
for connection? I hate to say after a fixed amount of time passed after
the server starts, start the
client program, and it tries to connect to the server fixed number of times
before it quits.

“ran zhang” <rzhang@vamcointernational.com> wrote in message
news:a2p36l$jdo$1@inn.qnx.com

Hi All:

I’m writing a Server under qnx, when I try to bind a socket, I
specfically try to bind to
port #2000, and in my Client side, I try to connect to port #2000.
However… bind function
often fails when it tries to bind to port #2000. This function always
works
if i let it bind
to a open port randomly, and pass in that port # to my client’s program as
an arg. But
I can’t ask the customer to entered the port # printed out by t he server
program in the shell
and pass it in in order to start my client program. Is there any more
elegant way of handling this?
Maybe a higher port #?

Another question. how would the client know when the Server is ready
and
starting to listen for connection?

The normal means is by trying to connect .

I hate to say after a fixed amount of time passed after
the server starts, start the client program, and it tries to
connect to the server fixed number of times before it quits.

Yes

You could have a look at having your server start automaticaly by inetd

i dont see your answer for first part of my question regarding the Port #…
is that ‘yes’ referring to trying a higher port #?
or there is a better way doing it. ?


Mario Charest <goto@nothingness.com> wrote in message
news:a2p5ts$lec$1@inn.qnx.com

“ran zhang” <> rzhang@vamcointernational.com> > wrote in message
news:a2p36l$jdo$> 1@inn.qnx.com> …
Hi All:

I’m writing a Server under qnx, when I try to bind a socket, I
specfically try to bind to
port #2000, and in my Client side, I try to connect to port #2000.
However… bind function
often fails when it tries to bind to port #2000. This function always
works
if i let it bind
to a open port randomly, and pass in that port # to my client’s program
as
an arg. But
I can’t ask the customer to entered the port # printed out by t he
server
program in the shell
and pass it in in order to start my client program. Is there any more
elegant way of handling this?
Maybe a higher port #?

Another question. how would the client know when the Server is ready
and
starting to listen for connection?

The normal means is by trying to connect .

I hate to say after a fixed amount of time passed after
the server starts, start the client program, and it tries to
connect to the server fixed number of times before it quits.

Yes

You could have a look at having your server start automaticaly by inetd
\

ran zhang <rzhang@vamcointernational.com> wrote:

i dont see your answer for first part of my question regarding the Port #…
is that ‘yes’ referring to trying a higher port #?
or there is a better way doing it. ?

Without errno comming back from bind, this is just a guess.
Looking at function setsockopt(), and the option “SO_REUSEADDR”,
“SO_REUSEPORT”. You want to set this before call “bind()”.

-xtang

Mario Charest <> goto@nothingness.com> > wrote in message
news:a2p5ts$lec$> 1@inn.qnx.com> …

“ran zhang” <> rzhang@vamcointernational.com> > wrote in message
news:a2p36l$jdo$> 1@inn.qnx.com> …
Hi All:

I’m writing a Server under qnx, when I try to bind a socket, I
specfically try to bind to
port #2000, and in my Client side, I try to connect to port #2000.
However… bind function
often fails when it tries to bind to port #2000. This function always
works
if i let it bind
to a open port randomly, and pass in that port # to my client’s program
as
an arg. But
I can’t ask the customer to entered the port # printed out by t he
server
program in the shell
and pass it in in order to start my client program. Is there any more
elegant way of handling this?
Maybe a higher port #?

Another question. how would the client know when the Server is ready
and
starting to listen for connection?

The normal means is by trying to connect .

I hate to say after a fixed amount of time passed after
the server starts, start the client program, and it tries to
connect to the server fixed number of times before it quits.

Yes

You could have a look at having your server start automaticaly by inetd
\

qnx doesnt support SO_REUSEPORT option in setsockopt at the socket level…
do i need to specify another level rather than SOL_SOCKET in order to use
this SO_REUSEPORT option in setsockopt()?


Xiaodan Tang <xtang@qnx.com> wrote in message
news:a2p84s$344$1@nntp.qnx.com

ran zhang <> rzhang@vamcointernational.com> > wrote:
i dont see your answer for first part of my question regarding the Port
#…
is that ‘yes’ referring to trying a higher port #?
or there is a better way doing it. ?

Without errno comming back from bind, this is just a guess.
Looking at function setsockopt(), and the option “SO_REUSEADDR”,
“SO_REUSEPORT”. You want to set this before call “bind()”.

-xtang

Mario Charest <> goto@nothingness.com> > wrote in message
news:a2p5ts$lec$> 1@inn.qnx.com> …

“ran zhang” <> rzhang@vamcointernational.com> > wrote in message
news:a2p36l$jdo$> 1@inn.qnx.com> …
Hi All:

I’m writing a Server under qnx, when I try to bind a socket, I
specfically try to bind to
port #2000, and in my Client side, I try to connect to port #2000.
However… bind function
often fails when it tries to bind to port #2000. This function
always
works
if i let it bind
to a open port randomly, and pass in that port # to my client’s
program
as
an arg. But
I can’t ask the customer to entered the port # printed out by t he
server
program in the shell
and pass it in in order to start my client program. Is there any more
elegant way of handling this?
Maybe a higher port #?

Another question. how would the client know when the Server is
ready
and
starting to listen for connection?

The normal means is by trying to connect .

I hate to say after a fixed amount of time passed after
the server starts, start the client program, and it tries to
connect to the server fixed number of times before it quits.

Yes

You could have a look at having your server start automaticaly by inetd


\