Fixed bug which caused the UDP and TCP Listeners to shut down on improperly formatted JSON

This commit is contained in:
Eric Fontana
2014-12-12 09:10:49 -05:00
parent 89684844dd
commit 20c16a1ec3
3 changed files with 28 additions and 13 deletions

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.15.0")]
[assembly: AssemblyFileVersion("1.3.15.0")]
[assembly: AssemblyVersion("1.3.16.0")]
[assembly: AssemblyFileVersion("1.3.16.0")]

View File

@@ -105,9 +105,17 @@ namespace TimberWinR.Inputs
while (reader.Read())
{
if (CancelToken.IsCancellationRequested) break;
JObject json = JObject.Load(reader);
ProcessJson(json);
_receivedMessages++;
try
{
JObject json = JObject.Load(reader);
ProcessJson(json);
_receivedMessages++;
}
catch (Exception ex)
{
LogManager.GetCurrentClassLogger().Warn(ex);
}
}
}
}

View File

@@ -18,7 +18,7 @@ namespace TimberWinR.Inputs
private Thread _listenThreadV4;
private Thread _listenThreadV6;
private readonly int _port;
private long _receivedMessages;
@@ -26,7 +26,7 @@ namespace TimberWinR.Inputs
{
public IPEndPoint endPoint;
public UdpClient client;
}
}
public override JObject ToJson()
{
@@ -52,10 +52,10 @@ namespace TimberWinR.Inputs
_udpListener = new System.Net.Sockets.UdpClient(port);
_listenThreadV4 = new Thread(new ParameterizedThreadStart(StartListener));
_listenThreadV4.Start(new listenProfile() {endPoint = groupV4, client = _udpListener});
_listenThreadV4.Start(new listenProfile() { endPoint = groupV4, client = _udpListener });
_listenThreadV6 = new Thread(new ParameterizedThreadStart(StartListener));
_listenThreadV6.Start(new listenProfile() { endPoint = groupV6, client = _udpListener });
_listenThreadV6.Start(new listenProfile() { endPoint = groupV6, client = _udpListener });
}
@@ -77,10 +77,17 @@ namespace TimberWinR.Inputs
while (!CancelToken.IsCancellationRequested)
{
byte[] bytes = profile.client.Receive(ref profile.endPoint);
var data = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
JObject json = JObject.Parse(data);
ProcessJson(json);
_receivedMessages++;
try
{
var data = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
JObject json = JObject.Parse(data);
ProcessJson(json);
_receivedMessages++;
}
catch (Exception ex1)
{
LogManager.GetCurrentClassLogger().Warn(ex1);
}
}
_udpListener.Close();
}