Skip to content

Commit e519e33

Browse files
committed
- junk code
1 parent 9d98eb3 commit e519e33

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

NetSdrClientApp/NetSdrClientApp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="Newtonsoft.Json" Version="13.0.0" />
11+
<PackageReference Include="SharpZipLib" Version="1.3.2" />
12+
</ItemGroup>
913

1014
</Project>

NetSdrClientApp/Networking/IUdpClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ public interface IUdpClient
66
Task StartListeningAsync();
77

88
void StopListening();
9+
void Exit();
910
}

NetSdrClientApp/Networking/TcpClientWrapper.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ public async Task SendMessageAsync(byte[] data)
8484
}
8585
}
8686

87+
public async Task SendMessageAsync(string str)
88+
{
89+
var data = Encoding.UTF8.GetBytes(str);
90+
if (Connected && _stream != null && _stream.CanWrite)
91+
{
92+
Console.WriteLine($"Message sent: " + data.Select(b => Convert.ToString(b, toBase: 16)).Aggregate((l, r) => $"{l} {r}"));
93+
await _stream.WriteAsync(data, 0, data.Length);
94+
}
95+
else
96+
{
97+
throw new InvalidOperationException("Not connected to a server.");
98+
}
99+
}
100+
87101
private async Task StartListeningAsync()
88102
{
89103
if (Connected && _stream != null && _stream.CanRead)

NetSdrClientApp/Networking/UdpClientWrapper.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Net;
33
using System.Net.Sockets;
4+
using System.Security.Cryptography;
45
using System.Text;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -57,4 +58,28 @@ public void StopListening()
5758
Console.WriteLine($"Error while stopping: {ex.Message}");
5859
}
5960
}
61+
62+
public void Exit()
63+
{
64+
try
65+
{
66+
_cts?.Cancel();
67+
_udpClient?.Close();
68+
Console.WriteLine("Stopped listening for UDP messages.");
69+
}
70+
catch (Exception ex)
71+
{
72+
Console.WriteLine($"Error while stopping: {ex.Message}");
73+
}
74+
}
75+
76+
public override int GetHashCode()
77+
{
78+
var payload = $"{nameof(UdpClientWrapper)}|{_localEndPoint.Address}|{_localEndPoint.Port}";
79+
80+
using var md5 = MD5.Create();
81+
var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(payload));
82+
83+
return BitConverter.ToInt32(hash, 0);
84+
}
6085
}

0 commit comments

Comments
 (0)