Skip to content

Commit

Permalink
Fixes #4 Added a 5 seconds timeout during trying to connect with the …
Browse files Browse the repository at this point in the history
…console
  • Loading branch information
mkeymolen committed Apr 22, 2017
1 parent efbecac commit de46149
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>DavisVantage.WeatherReader reads weatherdata from a Davis Vantage weatherstation console. Please find more information on how to use on our project site @ github</Description>
<Copyright>Copyright 2016</Copyright>
<VersionPrefix>1.6.1-alpha</VersionPrefix>
<VersionPrefix>1.6.2-alpha</VersionPrefix>
<Authors>Michael Keymolen</Authors>
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
<DefineConstants>$(DefineConstants);LIBLOG_PORTABLE</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ public bool Connect()
}
_tcpClient = new TcpClient();
// wait for connection
_tcpClient.ConnectAsync(Settings.IpAddress, Settings.Port).Wait();

if (!_tcpClient.ConnectAsync(Settings.IpAddress, Settings.Port).Wait(TimeSpan.FromSeconds(5)))
{
s_logger.Error($"Could not connect to {Settings?.IpAddress}:{Settings?.Port}");
return false;
}
return _tcpClient.Connected;
}
catch (Exception)
{
s_logger.Error($"Could not connect to {Settings?.IpAddress}:{Settings?.Port}");
s_logger.Error($"Could not connect to {Settings?.IpAddress}:{Settings?.Port}");
return false;
}

Expand Down Expand Up @@ -150,7 +155,6 @@ private bool WakeUp()
return false;
}
}

private void ReadUntilAckByte(NetworkStream networkStream)
{
const int ACK = 6;
Expand Down

0 comments on commit de46149

Please sign in to comment.