TCP/IP Port 2300 (Telnet) Disconnect Detection
TCP/IP Port 2300 (Telnet) Disconnect Detection
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.
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
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)
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)
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
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
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
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
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
Brian
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
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.
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.
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
Hi,
I'm interested in the CheckEthernetCable() function. I can't find it on the nburn folder.
Where is this located?
Thanks,
Victor
I'm interested in the CheckEthernetCable() function. I can't find it on the nburn folder.
Where is this located?
Thanks,
Victor
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
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" );
}
}
/**
* 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" );
}
}
Re: TCP/IP Port 2300 (Telnet) Disconnect Detection
rnixon,
Thanks for the reply!
I'll try EtherLink().
Thanks again,
Victor
Thanks for the reply!
I'll try EtherLink().
Thanks again,
Victor