led连接还原

master
tq 2 months ago
parent b3b36d93e4
commit 24abed6bd8

@ -135,45 +135,39 @@ public class LedClient
_socket = null;
}
}
private static readonly object Locker = new object();
private static bool InnerSend(byte[] bytes)
{
lock (Locker)
if (_socket?.Connected ?? false)
{
try
{
_socket.Send(bytes);
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)}");
return true;
}
catch (SocketException ex)
{
Log.Error($"Failed to send data. Reason: {ex.Message}");
return false;
}
}
else
{
Connect();
if (_socket?.Connected ?? false)
{
try
{
_socket.Send(bytes);
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)}");
return true;
}
catch (SocketException ex)
{
Log.Error($"Failed to send data. Reason: {ex.Message}");
return false;
}
_socket.Send(bytes);
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)} after reconnect");
return true;
}
else
{
Connect();
if (_socket?.Connected ?? false)
{
_socket.Send(bytes);
Log.Info($"Sent {BitUtls.BytesToHexStr(bytes)} after reconnect");
return true;
}
else
{
Log.Error($"Failed to reconnect and send data.");
return false;
}
}
Log.Error($"Failed to reconnect and send data.");
return false;
}
}
}

Loading…
Cancel
Save