TCP/IP Connect timeout

I have a program that uses Modbus over TCP/IP (v5.0) to communicate with 20
separate devices.

Everything works great until a remote device gets taken off line. Then, it
takes about 70 seconds before “connect” returns a failure. I can set an
alarm timer to make this shorter (I’m looking for about 2 seconds), but then
I get failures talking to the other devices (apparently alarming out of a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services

You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <jeffadler.at.bigfoot.dot.com@nowhere.com> wrote:

I have a program that uses Modbus over TCP/IP (v5.0) to communicate with 20
separate devices.

Everything works great until a remote device gets taken off line. Then, it
takes about 70 seconds before “connect” returns a failure. I can set an
alarm timer to make this shorter (I’m looking for about 2 seconds), but then
I get failures talking to the other devices (apparently alarming out of a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services

How is the condition handled when the remote device is really down??

I can see programming a non-blocking connect, waiting ~2 seconds for select,
if it doesn’t complete, next time through (a few seconds later) try a select
again, etc.

Will the connect keep trying indefinately, or will I have to do another
connect again? When will I know that the connect failed?

Can I repeatedly call connect every 2 seconds and then call select?

Thanks,

Jeff.

“Sean Boudreau” <seanb@qnx.com> wrote in message
news:cvo4ku$b82$1@inn.qnx.com

You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:
I have a program that uses Modbus over TCP/IP (v5.0) to communicate with
20
separate devices.

Everything works great until a remote device gets taken off line. Then,
it
takes about 70 seconds before “connect” returns a failure. I can set an
alarm timer to make this shorter (I’m looking for about 2 seconds), but
then
I get failures talking to the other devices (apparently alarming out of a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services

Jeffrey Adler wrote:

How is the condition handled when the remote device is really down??

I can see programming a non-blocking connect, waiting ~2 seconds for select,
if it doesn’t complete, next time through (a few seconds later) try a select
again, etc.

Yes … it’s a common practise to have a ‘state machine’ for every
fieldbus device, at least at the protocol level.


Regards

Armin


Will the connect keep trying indefinately, or will I have to do another
connect again? When will I know that the connect failed?

Can I repeatedly call connect every 2 seconds and then call select?

Thanks,

Jeff.

“Sean Boudreau” <> seanb@qnx.com> > wrote in message
news:cvo4ku$b82$> 1@inn.qnx.com> …

You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:

I have a program that uses Modbus over TCP/IP (v5.0) to communicate with
20
separate devices.

Everything works great until a remote device gets taken off line. Then,
it
takes about 70 seconds before “connect” returns a failure. I can set an
alarm timer to make this shorter (I’m looking for about 2 seconds), but
then
I get failures talking to the other devices (apparently alarming out of a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services
\

Is there any way to tell when a non-blocking connect() has given up?

Jeff.

“Armin Steinhoff” <a-steinhoff@web.de> wrote in message
news:cvpgd6$b2u$1@inn.qnx.com

Jeffrey Adler wrote:
How is the condition handled when the remote device is really down??

I can see programming a non-blocking connect, waiting ~2 seconds for
select, if it doesn’t complete, next time through (a few seconds later)
try a select again, etc.

Yes … it’s a common practise to have a ‘state machine’ for every
fieldbus device, at least at the protocol level.


Regards

Armin



Will the connect keep trying indefinately, or will I have to do another
connect again? When will I know that the connect failed?

Can I repeatedly call connect every 2 seconds and then call select?

Thanks,

Jeff.

“Sean Boudreau” <> seanb@qnx.com> > wrote in message
news:cvo4ku$b82$> 1@inn.qnx.com> …

You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:

I have a program that uses Modbus over TCP/IP (v5.0) to communicate with
20
separate devices.

Everything works great until a remote device gets taken off line. Then,
it
takes about 70 seconds before “connect” returns a failure. I can set an
alarm timer to make this shorter (I’m looking for about 2 seconds), but
then
I get failures talking to the other devices (apparently alarming out of
a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services

Jeffrey Adler wrote:

Is there any way to tell when a non-blocking connect() has given up?

return value == -1 plus value of errno

Regards

Armin

Jeff.

“Armin Steinhoff” <> a-steinhoff@web.de> > wrote in message
news:cvpgd6$b2u$> 1@inn.qnx.com> …

Jeffrey Adler wrote:

How is the condition handled when the remote device is really down??

I can see programming a non-blocking connect, waiting ~2 seconds for
select, if it doesn’t complete, next time through (a few seconds later)
try a select again, etc.

Yes … it’s a common practise to have a ‘state machine’ for every
fieldbus device, at least at the protocol level.


Regards

Armin



Will the connect keep trying indefinately, or will I have to do another
connect again? When will I know that the connect failed?

Can I repeatedly call connect every 2 seconds and then call select?

Thanks,

Jeff.

“Sean Boudreau” <> seanb@qnx.com> > wrote in message
news:cvo4ku$b82$> 1@inn.qnx.com> …


You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:


I have a program that uses Modbus over TCP/IP (v5.0) to communicate with
20
separate devices.

Everything works great until a remote device gets taken off line. Then,
it
takes about 70 seconds before “connect” returns a failure. I can set an
alarm timer to make this shorter (I’m looking for about 2 seconds), but
then
I get failures talking to the other devices (apparently alarming out of
a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services

Sorry, I wasn’t clear. I set the socket to non-blocking. Then I call
connect(). When it returns, I do a periodic select() waiting for write_fds
to indicate that it is OK to write, indicating that connect() has succeeded.

Assuming that the remote device is unavailable, connect will continue to
retry until it gives up. With a BLOCKING connect, this seems to be about 70
seconds.

Is there any way to tell, after calling connect(), and after doing select()
for a while, when a NON-BLOCKING connect() has given up?

Thanks,

Jeff.

“Armin Steinhoff” <a-steinhoff@web.de> wrote in message
news:cvtdgo$5ds$1@inn.qnx.com

Jeffrey Adler wrote:
Is there any way to tell when a non-blocking connect() has given up?

return value == -1 plus value of errno

Regards

Armin


Jeff.

“Armin Steinhoff” <> a-steinhoff@web.de> > wrote in message
news:cvpgd6$b2u$> 1@inn.qnx.com> …

Jeffrey Adler wrote:

How is the condition handled when the remote device is really down??

I can see programming a non-blocking connect, waiting ~2 seconds for
select, if it doesn’t complete, next time through (a few seconds later)
try a select again, etc.

Yes … it’s a common practise to have a ‘state machine’ for every
fieldbus device, at least at the protocol level.


Regards

Armin



Will the connect keep trying indefinately, or will I have to do another
connect again? When will I know that the connect failed?

Can I repeatedly call connect every 2 seconds and then call select?

Thanks,

Jeff.

“Sean Boudreau” <> seanb@qnx.com> > wrote in message
news:cvo4ku$b82$> 1@inn.qnx.com> …


You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:


I have a program that uses Modbus over TCP/IP (v5.0) to communicate
with 20
separate devices.

Everything works great until a remote device gets taken off line.
Then, it
takes about 70 seconds before “connect” returns a failure. I can set
an
alarm timer to make this shorter (I’m looking for about 2 seconds),
but then
I get failures talking to the other devices (apparently alarming out
of a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services

You can do:

{
int err, len;

len = sizeof(err);
getsockopt(sock, SOL_SOCKER, SO_ERROR, &err, &len);
}

if err == 0, the connect succeeded, otherwise it’s the errno.

You might want to check out “Unix Networking Programming”
by Stevens for more info.

Regards,

-seanb

Jeffrey Adler <jeffadler.at.bigfoot.dot.com@nowhere.com> wrote:

Sorry, I wasn’t clear. I set the socket to non-blocking. Then I call
connect(). When it returns, I do a periodic select() waiting for write_fds
to indicate that it is OK to write, indicating that connect() has succeeded.

Assuming that the remote device is unavailable, connect will continue to
retry until it gives up. With a BLOCKING connect, this seems to be about 70
seconds.

Is there any way to tell, after calling connect(), and after doing select()
for a while, when a NON-BLOCKING connect() has given up?

Thanks,

Jeff.

“Armin Steinhoff” <> a-steinhoff@web.de> > wrote in message
news:cvtdgo$5ds$> 1@inn.qnx.com> …
Jeffrey Adler wrote:
Is there any way to tell when a non-blocking connect() has given up?

return value == -1 plus value of errno

Regards

Armin


Jeff.

“Armin Steinhoff” <> a-steinhoff@web.de> > wrote in message
news:cvpgd6$b2u$> 1@inn.qnx.com> …

Jeffrey Adler wrote:

How is the condition handled when the remote device is really down??

I can see programming a non-blocking connect, waiting ~2 seconds for
select, if it doesn’t complete, next time through (a few seconds later)
try a select again, etc.

Yes … it’s a common practise to have a ‘state machine’ for every
fieldbus device, at least at the protocol level.


Regards

Armin



Will the connect keep trying indefinately, or will I have to do another
connect again? When will I know that the connect failed?

Can I repeatedly call connect every 2 seconds and then call select?

Thanks,

Jeff.

“Sean Boudreau” <> seanb@qnx.com> > wrote in message
news:cvo4ku$b82$> 1@inn.qnx.com> …


You can try a non blocking connect(). Set the socket
to non blocking and select() will wake up when it’s
completed. Posix says wakeup for write but I think
some older stacks woke up for read.

Regards,

-seanb

Jeffrey Adler <> jeffadler.at.bigfoot.dot.com@nowhere.com> > wrote:


I have a program that uses Modbus over TCP/IP (v5.0) to communicate
with 20
separate devices.

Everything works great until a remote device gets taken off line.
Then, it
takes about 70 seconds before “connect” returns a failure. I can set
an
alarm timer to make this shorter (I’m looking for about 2 seconds),
but then
I get failures talking to the other devices (apparently alarming out
of a
connect doesn’t stop TCP/IP from trying).

Does anyone have a decent solution to this??

Thanks,

Jeff Adler
Automation Services