TCP/IP Port 2300 (Telnet) Disconnect Detection

Discussion to talk about software related topics only.
Post Reply
BMillikan
Posts: 14
Joined: Thu Dec 23, 2010 7:56 am

TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by BMillikan »

Is there a relatively easy way to detect when the connection between a server and client is broken? What is the best way to do this? I have a fairly simple operation where I am taking data from a serial port and sending it to the ethernet port using "read()" and "write()". However if the ethernet connection is broken, the program stops after a fairly long period of time. It seems as though several of the commands from the serial port are buffered up in the "write()" command somehow. Is this true? If I disconnect for a short period of time and then reconnect, I get several responses in a row. Any ideas/help would be appreciated.
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by seulater »

First, know that detecting a connection between server and client is not limited to Netburner but all networked products.

The way i have gotten around this issue, is that every 20 seconds i send a "heartbeat" char from the client to the server and when the server detects this patterned string it echoes it back. If the server does not get this "heartbeat" packet within that time it closes the connection and goes back to a listening state waiting for a new connection to be made.

If you want to detect if the LAN cable is pulled out you can detect that by using

if( CheckEthernetCable() == false)
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by pbreed »

this is the TCP keep alive problem.

The core problem is that when no data is flowing no packets are flowing so a quiet disconnect and idle
line have identical behavior.

Its in the basic design of the protocol.

The best work around is to use TCP keep alive
See the nburn\examples\tcp\TCP_simple_keepalive

Paul
BMillikan
Posts: 14
Joined: Thu Dec 23, 2010 7:56 am

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by BMillikan »

The netburner is the client, the server is the device I'm trying to write to. If I write to a socket that is physically disconnected (ethernet cable is unplugged), the netburner stops (freezes) on the "write()" command. There was an example that opens the port, writes and then closes the port. This method works, but slows down my connection. I was able to run this for over 12 hours. Is there any other way to test for a valid connection before I write to the port? Does any of this make sense?

Brian
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by rnixon »

Did you try either of the earlier suggestions:
1. Add keep-alive to your code
2. Check for the cable connection before you call write()

It seems that if you are working with a very poor connection, or a situation in which the cable keeps getting unplugged, you need to add more error checking than on a connection that is usually working and a cable that is usually plugged in.
vsabino
Posts: 32
Joined: Wed May 14, 2008 8:45 am

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by vsabino »

Hi,

I'm interested in the CheckEthernetCable() function. I can't find it on the nburn folder.
Where is this located?

Thanks,
Victor
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by rnixon »

I was referring to ethernet link. The mod5270 factory example has the following. I'm assuming if I have link there's a good chance the cable is plugged in.

/**
* Display the Ethernet link status. This code is only valid in release builds
* because the network builds use Ethernet debugging.
*/
void ShowEthernetLinkStatus( void )
{
if ( EtherLink() )
{
iprintf( "Link Status: UP, " );

( EtherSpeed100() ) ?
iprintf( "100 Mb/s, " ):
iprintf( "10 Mb/s, " );

( EtherDuplex() ) ?
iprintf( "Full Duplex\r\n" ):
iprintf( "Half Duplex\r\n" );
}
else
{
iprintf( "Link Status: DOWN\r\n" );
}
}
vsabino
Posts: 32
Joined: Wed May 14, 2008 8:45 am

Re: TCP/IP Port 2300 (Telnet) Disconnect Detection

Post by vsabino »

rnixon,

Thanks for the reply!
I'll try EtherLink().


Thanks again,
Victor
Post Reply