NetworkComms.Net icon indicating copy to clipboard operation
NetworkComms.Net copied to clipboard

Possible Bug when trying to reconnect with unmanaged connection

Open jpvdmerwe opened this issue 9 years ago • 5 comments

Hi,

I might have found a possible bug when trying to reconnect with an unmanaged connection.

First I create my unmanaged connection:

SendReceiveOptions optionsToUse = new SendReceiveOptions<NullSerializer>();
ConnectionInfo connectionInfo = new ConnectionInfo("192.168.0.2", 10001, ApplicationLayerProtocolStatus.Disabled);

var conn = TCPConnection.GetConnection(connectionInfo, optionsToUse);

After this I check the conn.ConnectionInfo.ConnectionState to see if it is ConnectionState.Established.

Here is my testing scenario:

  1. Start application
  2. Ethernet cable plugged in - ConnectionState is Established
  3. Ethernet cable is removed, a timer will create a new connection after 1 minute - ConnectionState is still Established.

Am I using the ConnectionState incorrectly?

Update: If you do not use the CloseConnection method before creating the new connection it will use the last ConnectionInfo for the IP / Port. Not sure if this is still a bug, for now everything seems fine.

Kind Regards, JP

jpvdmerwe avatar May 05 '16 07:05 jpvdmerwe

Hi JP, AFAIK the value of ConnectionState cannot be relied upon for unmanaged connections. This state is primarily intended for use with managed connections. That being the case the bug is probably the connection state for unmanaged connections should always be ConnectionState.Undefined. I'll raise this as a bug for now. Marc

MarcFletcher avatar May 05 '16 12:05 MarcFletcher

Hi Marc,

Thanks for the response. I'm using the LastTrafficTime from the ConnectionInfo to determine whether to close the connection and attempt to reconnect.

Do you perhaps have a better approach?

JP

jpvdmerwe avatar May 06 '16 20:05 jpvdmerwe

JP, in 95% of cases the managed connection is what you want to be using. How come you are using unmanaged connections?

MarcFletcher avatar May 08 '16 13:05 MarcFletcher

Marc,

I do use the managed connections when communicating with other NetworkComms.Net applications, however I use the unmanaged connections when communicating with 3rd party devices like GPS Devices, Serial Comms over TCP/IP devices, etc.

jpvdmerwe avatar May 09 '16 04:05 jpvdmerwe

I did too

cimyong avatar Dec 05 '19 03:12 cimyong