Implement IDisposable for CommandStream

This commit is contained in:
2019-04-27 13:59:01 +02:00
parent 76bbefd729
commit 7467d5ba81
4 changed files with 38 additions and 32 deletions

View File

@@ -52,36 +52,37 @@ namespace PlantBox.Broker
private void ClientLoop(TcpClient client)
{
var commandStream = new CommandStream(client.GetStream());
try
using (var commandStream = new CommandStream(client.GetStream()))
{
while (client.Connected)
try
{
var packet = commandStream.Receive();
Log($"Received command from {client.Client.RemoteEndPoint}");
Log(packet.ToString());
switch (packet.Command)
while (client.Connected)
{
case Command.Captors:
CaptorsCommand(commandStream, packet);
break;
case Command.Historic:
HistoricCommand(commandStream, packet);
break;
case Command.Info:
InfoCommand(commandStream, packet);
break;
case Command.Ping:
PingCommand(commandStream, packet);
break;
var packet = commandStream.Receive();
Log($"Received command from {client.Client.RemoteEndPoint}");
Log(packet.ToString());
switch (packet.Command)
{
case Command.Captors:
CaptorsCommand(commandStream, packet);
break;
case Command.Historic:
HistoricCommand(commandStream, packet);
break;
case Command.Info:
InfoCommand(commandStream, packet);
break;
case Command.Ping:
PingCommand(commandStream, packet);
break;
}
}
}
}
catch (Exception ex)
{
Log($"Client disconnected: {ex.Message}");
catch (Exception ex)
{
Log($"Client disconnected: {ex.Message}");
}
}
}